Hi,
I've created a custom FreedomUI page for AccountAddress object. I'd like to implement some kind of automation for two lookup fields: Country and Region. It consists of two parts:
1. When I choose a region from list, the country should be set to region's country. For example, if I choose Texas region, I expect that country will be set to United States
2. When I choose a country, regions lookup should display only these regions, which are connected with selected country.
I haven't any problem with implementation of the first part. But the second part doesn't work I expected. I use handler for crt.LoadDataRequest to append a filter parameter when loading regions list. The problem is that this handler runs only once, at first list load. It doesn't execute when I change country, although I trigger such request from other handler (crt.HandleViewModelAttributeChangeRequest). Here is the crucial of my code:
{
request: 'crt.LoadDataRequest',
handler: async (request, next) => {
if (request.dataSourceName === 'Region_List_DS') {
const predefinedFilter = await request.$context.Region_filter;
request.parameters.push({
type: "filter",
value: predefinedFilter
});
}
return await next?.handle(request);
}
},
{
request: 'crt.HandleViewModelAttributeChangeRequest',
handler: async (request, next) => {
if (request.attributeName === 'EvCountry' && request.value?.value != null && (request.oldValue?.value == null || request.value.value !== request.oldValue.value)) {
const countryId = request.value?.value;
request.$context.EvRegion_filter = {
"items": {
"1954b2e1-ea91-4014-b785-cda17020595c": {
"items": {
"CustomFilters": {
"items": {
"customFilterCountry_Region_1664cb4d-2690-48d6-bcdf-0c8075824efa": {
"filterType": 1,
"comparisonType": 3,
"isEnabled": true,
"trimDateTimeParameterToDate": false,
"leftExpression": {
"expressionType": 0,
"columnPath": "Country"
},
"rightExpression": {
"expressionType": 2,
"parameter": {
"dataValueType": 10,
"value": countryId
}
}
}
},
"logicalOperation": 0,
"isEnabled": true,
"filterType": 6
}
},
"logicalOperation": 0,
"isEnabled": true,
"filterType": 6
}
},
"logicalOperation": 0,
"isEnabled": true,
"filterType": 6
};
const handlerChain = sdk.HandlerChainService.instance;
const result = await handlerChain.process({
type: "crt.LoadDataRequest",
$context: request.$context,
config: {
loadType: "load"
},
dataSourceName: "EvRegion_List_DS",
});
}
return next?.handle(request);
}
}
The problem is that my trigger (handlerChain.process call) doesn't run crt.LoadDataRequest, and result variable contains full, unfiltered list of regions.