return name in lookup using guid in c#
Hi first post and on my journey to developing in Creatio 8.2
I been reading a lot on the forums but i maybe confused with some of the information out there. I been trying to write a simple reusable class to simple return a name from a lookup. I have a guid id. I been trying to use ExecuteScalar, but should I be using Execute? I have attempted both ways but no matter which way I get CS1061 missing assembly reference. I'm not sure if its because its not available in this version builder or just something I missed. I would appreciate any help
Like
You can see an example of that here, which uses the Select class to read the value: https://customerfx.com/article/reusable-function-for-retrieving-the-id-of-a-lookup-item-from-its-name-in-bpmonline/
that approach would work for anything that inherits from BaseLookup since it would always have a "Name" column, however, would fail for anything that inherits from BaseEntity (since it's name might be something like "UsrName"). A better approach would be to use the Entity class to get it's primary display value - something like this:
// using Terrasoft.Core.Entities; public string GetRecordDisplayValue(string entityType, Guid id) { var schema = UserConnection.EntitySchemaManager.GetInstanceByName(entityType); var entity = schema.CreateEntity(UserConnection); if (entity.FetchFromDB(id)) { return entity.PrimaryDisplayColumnValue; } return string.Empty; }
The usage would look like:
var cityName = GetRecordDisplayValue("City", cityId); // or var accountName = GetRecordDisplayValue("Account", accId); // or var customName = GetRecordDisplayValue("UsrCustom", someId);
Ryan
Hello,
Do I understand correctly that your task is to return the name of the lookup from the Lookup table, having the lookup ID in the table?
If not, could you explain your business task in more detail? Perhaps a screenshot or code snippet will give us a better understanding of the task.
Also, if you encounter the CS1601 error during your implementation wit Execute, ExecuteScalar methods, please check out this documentation on Creatio Academy if your code follows the recommendations in the article - https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…;
Thank you.
You can see an example of that here, which uses the Select class to read the value: https://customerfx.com/article/reusable-function-for-retrieving-the-id-of-a-lookup-item-from-its-name-in-bpmonline/
that approach would work for anything that inherits from BaseLookup since it would always have a "Name" column, however, would fail for anything that inherits from BaseEntity (since it's name might be something like "UsrName"). A better approach would be to use the Entity class to get it's primary display value - something like this:
// using Terrasoft.Core.Entities; public string GetRecordDisplayValue(string entityType, Guid id) { var schema = UserConnection.EntitySchemaManager.GetInstanceByName(entityType); var entity = schema.CreateEntity(UserConnection); if (entity.FetchFromDB(id)) { return entity.PrimaryDisplayColumnValue; } return string.Empty; }
The usage would look like:
var cityName = GetRecordDisplayValue("City", cityId); // or var accountName = GetRecordDisplayValue("Account", accId); // or var customName = GetRecordDisplayValue("UsrCustom", someId);
Ryan
Ryan Farley,
Thanks!! By reading your comment and supplied link I have a better understanding how to attack future problems. :)