
Filtering lookups on a Freedom UI page is something new in 8.0.10. However, even in 8.0.10 there are still some issues with filtering lookups. I do expect lookup filtering to improve for Freedom UI in versions to come, however, there is still a need to be able to dynamically filter a lookup with complex conditions at runtime. This article will outline how to do this for a lookup on Freedom UI pages, giving you full control over the conditions for the filter.
Note: When a lookup is opened on a Freedom UI page, the lookup makes a crt.LoadDataRequest request to obtain its data. This request can be handled/intercepted and filter conditions can be added so the data received by the lookup is filtered to match the provided conditions.
To filter a lookup on a Freedom UI page, we’ll need to know the attribute name for the lookup field in the model, and then we’re add a handler for any time anything on the page makes a request to load it’s datasource. If the requested datasource is for our lookup’s bound field, we’ll apply a filter to the request. In the example for this article, we’ll use a scenario of filtering the Case contact lookup to only show contacts for the selected Account on the Case. In 8.0.10, this can be implemented as a business rule, however, we’re just using this as an example (which also could be added to 8.0.9 now as well).
First, we’ll need to locate the lookup control so we can determine it’s bound attribute name. For the case page, we’ll see the following for the Contact lookup in the viewConfigDiff for the page:
Notice the name of the attribute the control is bound to (highlighted in the screenshot). This will correspond with the following attribute in the viewModelConfig, which shows it’s bound to the Contact column for the Case:
For the case page, the “LookupAttribute_c08bwtk” attribute is what we’ll need to look for when it requests that it’s data source is loaded. The name of the datasource will be the attribute name followed by “_List_DS”. For this attribute, we’ll be looking for the request to load the data for the datasource named “LookupAttribute_c08bwtk_List_DS”.
The request handler will look as follows (Note, be sure to also add the “@creatio-devkit/common” to the page as sdk):
{ request: "crt.LoadDataRequest", handler: async (request, next) => { // filter the contact lookup for the account if(request.dataSourceName !== "LookupAttribute_ctwt6pv_List_DS") { return await next?.handle(request); } // get the account const account = await request.$context.LookupAttribute_c08bwtk; if (account) { const filter = new sdk.FilterGroup(); await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Account", account.value); // note, these lines are only needed due to an issue with filters in Creatio-DevKit SDK // expected to be fixed in Creatio 8.1 const newFilter = Object.assign({}, filter); newFilter.items = filter.items; request.parameters.push({ type: "filter", value: newFilter }); } return await next?.handle(request); } }
The end result will be that the Contact lookup will only show the contact’s for the Account on the Case.
One side note: As of Creatio 8.0.10, lookups only request their data once. Meaning, the first time the user clicks the dropdown. So, if you set a filter, then the user changes the fields you’re using for the filter, it won’t fire it’s crt.LoadDataRequest request again, allowing you to apply the filter again based on the new values (it will still use the original values). I’m sure this will change in future versions, but this is how it works as of 8.0.10.
Subscribe To Our Newsletter
Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!
You have Successfully Subscribed!