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 all,

       I add an attribute which type is LOOKUP to a custom page like this

      attributes: {

                  "ContactId": {

                          "dataValueType": this.Terrasoft.DataValueType.LOOKUP,

                          "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,

                   }

      }

 

      And then, I want its datasource is Filtered Contacts with condition is "he/she has mobile phone number". I know "lookupListConfig", but can't set Contacts is the datasource. Please help me to do that.

Many thanks

Like 0

Like

4 comments

From where I stay it's much easier to add the "contact" column into the related object and then apply the filtration with a business rule. 

attributes: {
"WO": {
	dataValueType: this.Terrasoft.DataValueType.LOOKUP,
	type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
	caption: "Some caption",
	hideActions: true,
	value: {
		value: "",
		displayValue: ""
	},
	referenceSchema: {
		name: "Contact",
		primaryColumnName: "Id",
		primaryDisplayColumnName: "Name"
	},
		referenceSchemaName: "Contact"
}
}
methods{
 
setWO: function(){
   this.set("WO", XXXXXXXXXXXX)
}
}

 

Eugene Podkovka,

Hi Eugene,

        Because I did a custom campaign element, I don't have any object to add relationship to Contact.

https://academy.bpmonline.com/documents/technic-sdk/7-13/adding-custom-…

Thanks

Kirill Krylov CPA,

Hi Kirill

    It works well

Thanks

Show all comments