Community
Showing results for 
Search instead for 
Do you mean 
Reply

Loop through records of a custom SubEntity & get field values

Accepted Solution Solved
Copper Contributor
Posts: 10
Country: USA
Accepted Solution

Loop through records of a custom SubEntity & get field values

I'm attempting to access the values in a preexisting custom SubEntity, and I'm stuck. This post is close to what I want, but it's not quite doing it for me. I have the CustomEntityDescriptor for the SubEntity I want, but this isn't helping me much.

 

Ultimately, I need to loop through each of the records in the SubEntity, and get the values of certain fields in each record. A few sample lines of code would be really helpful. Honestly, all I have going right now is a connection to the ACT! database via the SDK.


Accepted Solutions
Solution
Accepted by topic author dbenglund
‎09-25-2015 03:20 AM
Copper Contributor
Posts: 10
Country: USA

Re: Loop through records of a custom SubEntity & get field values

I figured it out.

 

From the beginning:

 

/*
 * Required:
 * 
 * using System.ComponentModel;
 * using Act.Framework;
 * using Act.Framework.CustomEntities;
 * using Act.Framework.MutableEntities;
 * using Act.Framework.ComponentModel;
 * using Act.Shared.Collections;
 */

// Start ACT! Framework
ActFramework act = new ActFramework();
act.LogOn(padFilePath, userName, password);

// Get custom entity & set manager for this entity
CustomEntityDescriptor TWSLicenseEntityDescriptor = act.CustomEntities.GetCustomEntityDescriptor("TWSLicense");
CustomSubEntityManager<TWSLicense> TWSLicenseManager = act.CustomEntities.GetSubEntityManager<TWSLicense>(TWSLicenseEntityDescriptor);

// Get the name of the field to be searched
DBFieldDescriptor HostId = TWSLicenseManager.GetCustomEntityFieldDescriptor("HostId", FieldNameType.Alias);

// Set simple sort criteria & get a list of all records in the the custom entity
SortCriteria[] sort = new SortCriteria[] { new SortCriteria(HostId, ListSortDirection.Descending) };
CustomEntityList<TWSLicense> TWSLicenseList = TWSLicenseManager.GetCustomEntities(sort);

// Get all of the fields using the first record
MutableEntity.FieldCollection fieldCollection = TWSLicenseList[0].Fields;
CustomSubEntity.CustomEntityFieldCollection customFields = TWSLicenseList[10].CustomSubEntityFields;

// Get the HostId as a string
string hostIdString = customFields[HostId.DisplayName.ToString(), FieldNameType.Alias].ToString();

// Now do whatever with the string
// In this case, testing by printing it to the console.
System.Console.WriteLine(hostIdString);

 

View solution in original post


All Replies
Solution
Accepted by topic author dbenglund
‎09-25-2015 03:20 AM
Copper Contributor
Posts: 10
Country: USA

Re: Loop through records of a custom SubEntity & get field values

I figured it out.

 

From the beginning:

 

/*
 * Required:
 * 
 * using System.ComponentModel;
 * using Act.Framework;
 * using Act.Framework.CustomEntities;
 * using Act.Framework.MutableEntities;
 * using Act.Framework.ComponentModel;
 * using Act.Shared.Collections;
 */

// Start ACT! Framework
ActFramework act = new ActFramework();
act.LogOn(padFilePath, userName, password);

// Get custom entity & set manager for this entity
CustomEntityDescriptor TWSLicenseEntityDescriptor = act.CustomEntities.GetCustomEntityDescriptor("TWSLicense");
CustomSubEntityManager<TWSLicense> TWSLicenseManager = act.CustomEntities.GetSubEntityManager<TWSLicense>(TWSLicenseEntityDescriptor);

// Get the name of the field to be searched
DBFieldDescriptor HostId = TWSLicenseManager.GetCustomEntityFieldDescriptor("HostId", FieldNameType.Alias);

// Set simple sort criteria & get a list of all records in the the custom entity
SortCriteria[] sort = new SortCriteria[] { new SortCriteria(HostId, ListSortDirection.Descending) };
CustomEntityList<TWSLicense> TWSLicenseList = TWSLicenseManager.GetCustomEntities(sort);

// Get all of the fields using the first record
MutableEntity.FieldCollection fieldCollection = TWSLicenseList[0].Fields;
CustomSubEntity.CustomEntityFieldCollection customFields = TWSLicenseList[10].CustomSubEntityFields;

// Get the HostId as a string
string hostIdString = customFields[HostId.DisplayName.ToString(), FieldNameType.Alias].ToString();

// Now do whatever with the string
// In this case, testing by printing it to the console.
System.Console.WriteLine(hostIdString);

 

New Member
Posts: 9
Country: USA

Re: Loop through records of a custom SubEntity & get field values

[ Edited ]

I used your code n it seem like i am missing something. Can you post also your HostiId class. I get an error. Could you try to explain this two lines and specially what are the 0 and 10 for:

MutableEntity.FieldCollection fieldCollection = TWSLicenseList[0].Fields;
CustomSubEntity.CustomEntityFieldCollection customFields = TWSLicenseList[10].CustomSubEntityFields;