Check if string contains lookup value

I have a bussiness process whicc extracts some values from a pdf, from the extraction on the pdf, there is a string value: "SecondaryPayerName".
now I have on a table "GCSeekPayer", some values and i need a script task to find if a value is in the "SecondaryPayerName" string.

I'm getting an error about the column "Id" not being found, but the column exists, the table has data, there are no spelling errors.

this is my script:

string secondaryPayerName = Get("SecondaryPayerName");

// Normalize: lowercase and remove spaces
string normalizedSecondaryPayerName = secondaryPayerName?.ToLower().Replace(" ", "") ?? "";

var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "GCSeekPayer");
esq.AddColumn("GCPayerName");
esq.AddColumn("Id");

var entities = esq.GetEntityCollection(UserConnection);

Guid payerCode = Guid.Empty;

foreach (var entity in entities) {
   string payerName = entity.GetTypedColumnValue("GCPayerName");

   if (!string.IsNullOrEmpty(payerName)) {
       // Normalize payer name too
       string normalizedPayerName = payerName.ToLower().Replace(" ", "");

       if (normalizedSecondaryPayerName.Contains(normalizedPayerName)) {
           payerCode = entity.GetTypedColumnValue("Id");
           break;
       }
   }
}

Set("SecondaryPayerCode", payerCode);

return true;

 

Like 0

Like

2 comments

Hello,

There can be a few reasons why you get the error that the column "Id" is not being found:


1. The column name might be case-sensitive or slightly different (e.g., "id" instead of "Id"). Double-check the exact name of the column in the Object Designer and ensure it matches the name used in the code.

2. If the "GCSeekPayer" entity was recently created or modified, the changes might not have been published. Publish the entity to ensure all changes are applied.

3. If the EntitySchemaQuery is not correctly initialized with the schema manager, it might not recognize the columns of the entity. Ensure that the UserConnection.EntitySchemaManager is correctly passed to the EntitySchemaQuery constructor.

4. If the current user does not have permission to access the "Id" column, it might result in an error. Check the permissions for the "GCSeekPayer" entity and ensure the user has access to the "Id" column.
 

Iryna Oriyenko,

Thanks for the reply, I found a solution here:

https://community.creatio.com/questions/get-primary-key-value-entity

I just needed this:

name your Id column:

var idColumnName = esq.AddColumn("Id").Name;

then you can get in your foreach loop:

entity.GetTypedColumnValue<Guid>(idColumnName);

Show all comments