Issue with Dynamic Email Filtering Based on Contact Selection
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
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.