Hello Community,

I am currently facing an issue with a model page that contains two lookup fields: one for contact and the other for email. My goal is to allow the user to select an email address associated with the selected contact, not just the primary email, but any email linked to that contact. To achieve this, I am using dynamic filtering for ContactCommunication to filter by the current contact and email communication type.

I’ve implemented this logic within the crt.LoadDataRequest handler because the email field is a simple dropdown and does not open a separate selection page.

The problem: 
When a contact is selected, I refresh the email list data source as expected. However, the email list is not properly reloading after a contact is deselected and reselected. In this case, the email filters do not update correctly. The issue is that the email list only reloads and applies the correct filters when I manually reselect the email field.

This behavior is causing a problem where the email dropdown is not correctly filtered based on the newly selected contact. Below is the code I am using for the handler:
 

handlers: /**SCHEMA_HANDLERS*/[
 {
   request: "crt.LoadDataRequest",
   handler: async (request, next) => {
     const emailDataSource = "UsrEntity_004572bDS_UsrEmailAddre_gzbqqxc_List_DS";
     const contactDataSource = "UsrEntity_004572bDS_UsrContact_7esmp6a_List_DS";

     if (request.dataSourceName === emailDataSource) {
       const lookupValue = await request.$context.UsrEntity_004572bDS_UsrContact_7esmp6a;
       console.log("Lookup Value:", lookupValue);

       if (lookupValue) {
         console.log("Filter Hit");
         const filter = new sdk.FilterGroup();
         filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Contact", lookupValue.value);
         filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "CommunicationType", "EE1C85C3-CFCB-DF11-9B2A-001D60E938C6");

         const newFilter = Object.assign({}, filter);
         newFilter.items = filter.items;
         console.log("Filter created");
         request.parameters.push({
           type: "filter",
           value: newFilter
         });
         console.log("Filter added to request");
       } else {
         console.log("Empty Lookup");
         // request.$context.UsrEntity_004572bDS_UsrEmailAddre_gzbqqxc = null;
         // request.$context.UsrEntity_004572bDS_UsrEmailAddre_gzbqqxc_List_DS = null;
       }
     }

     if (request.dataSourceName === contactDataSource) {
       console.log("Contact Selected, reloading email address list");
       // request.$context.UsrEntity_004572bDS_UsrEmailAddre_gzbqqxc = null;

       await request.$context.executeRequest({
         type: "crt.LoadDataRequest",
         $context: request.$context,
         config: { loadType: "reload", useLastLoadParameters: true },
         dataSourceName: emailDataSource
       });

       console.log("Email list reloaded successfully!");
     }

     return await next?.handle(request);
   }
 }
]/**SCHEMA_HANDLERS*/;
 

I would greatly appreciate it if you could look into this issue and suggest a solution.

Thank you!

Like 1

Like

1 comments

It is hard to tell what the issue is based on the code alone, in this situation, it would be better to run a proper debug to see what exactly went wrong. But, based on your description I can assume that there is something wrong with a refresh. Not with its code but rather with a place it is called. Try to use different approaches to it.

Show all comments

Hi,

I'm trying to pass the result of below "json" (in script task),

var schema = UserConnection.EntitySchemaManager.GetInstanceByName("Account");

    var entity = schema.CreateEntity(UserConnection);

    entity.FetchFromDB(id);

    json = Terrasoft.Core.Entities.Entity.SerializeToJson(entity);

 

to a process parameter and that process parameter needs to be passed to web service element as an request object. Since, the structure of "json" variable might vary, how to send this to a process parameter and eventually to web service element?

 

Any suggestions would be appreciated. Thanks.

Like 2

Like

5 comments

public bool FetchFromDB(object keyValue, bool useDisplayValues = true)

All the `FetchFromDB` methods return a bool, you could test the call.

SerializeToJson(Entity)

Should work.

 

I've had a great deal of trouble with JSON in Creatio in the past.   What's the error you're getting?

Hi Gareth,

Thanks for your reply.

Is there a sample as how this can be sent to webservice element? Use case is to handle this as an object while sending it to webservice element and not as a string. For example, the request at the web service element should look like below.

{

"objectName" : "Contact",

"Payload" : { "Name" : "Halludeen", "Age" : 24 }

}

But, if I pass it as a string then it looks like,

{

"requestJson" : "{\r\n \"ObjectName\": \"Contact\", \r\n \"Payload\": { \"Name\" : \"Halludeen\"}"

}

 

Let me know if you have any suggestions for this.

 

Thanks again.

 

 

 

Halludeen,

The only JSON library I have been able to get to work in Creatio is 

`System.Text.Json.JsonSerializer`.  You have to call it with the full namespace rather than add the namespace in a `using` statement, see here.

 

You could use the `Serialize<TValue>(TValue, JsonSerializerOptions)` method.  The technique is essentially the reverse of the example linked to above, create an object for the deserialised JSON in a module (see example), add the namespace to your process, create an object with the data you want to serialise, and serialise it using the above method into a string.  Hopefully that will work!

Gareth Osler,

Having said the above, I wrote in June,

By way of an epilogue, while the `System.Text.Json` namespace is available in a trial, for some reason it was not available in the dev environment I was using.  However classes in the `Terrasoft.Common.Json` namespace were available.  I was able to use the `Deserialize<T>(String)` method of the Json class.  (Note at the time of writing the `DeserializeDictionary(String)` method has a bug in it and cannot be used.)

You may have to use the above class to do the same.

Show all comments