Dynamic lookup filter on Freedom UI

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.

Like 1

Like

5 comments

Hello,

 

Thank you for the code and description!

 

We've verified the issue and discussed it with our core R&D team: in 8.0.9 there will be a possibility to add filtration business rules using wizard capabilities in Freedom UI. Please wait until this version is released and use this rule type to create dynamic filtration in Freedom UI interface.

Oleg Drobina,

as filtration business rules do not cover all cases of filtration, when can we wait for trigger fix?

We have tested in 8.0.9 and have the same issue as described



Thank you!

Vladimir

Vladimir Sokolov,

 

indeed filtration rules (along with static filtering business rules) don't cover all cases, but most of them. As for the list loading and the LoadDataRequest - in 8.1.0 there will be new "filterAttributes" attribute added for each list of each data source with the boolean "loadOnChange" property that will allow dynamic setup of filters in the lists (including combobox). It will look like this:

"filterAttributes": [
					{
						"loadOnChange": true,
						"name": "AccountItems_FILTER_BY_ACTIVE_ROWS"
					}

where AccountItems_FILTER_BY_ACTIVE_ROWS will be the filter itself. So in 8.1.0 all filtration cases should be covered by this functionality.

Hello,

 

Glad to inform you that in 8.1.1 we've added the possibility to use custom filters in page schema handlers when working with SDK. So you can upgrade your apps and you will be able to use custom filtration on the page.

Hi Oleg,

 

Do you have the code / Procedure to do this in 8.1.1 ?

Show all comments