Question

crt.LoadDataRequest does not seem to trigger?

I am trying to filter a Contact lookup so that it only displays contacts where Type.Name = "Prescriber".

 

Following this guide https://customerfx.com/article/dynamically-filtering-a-lookup-on-a-crea… I implemented a handler for "crt.LoadDataRequest". See code below:

 

		handlers: /**SCHEMA_HANDLERS*/[
 
			{
				request: "crt.LoadDataRequest",
				handler: async (request, next) => {
 
					console.log("request.dataSourceName: " + request.dataSourceName);
 
					if(request.dataSourceName !== "PDS_WlfPrescriber_u7mn5e4_List_DS") {
						return await next?.handle(request);
					}
 
					const filter = new sdk.FilterGroup();
					await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Type.Name", "Prescriber");
 
					console.log("filter:" + filter);
 
					// 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
					});
 
					console.log("request.parameters:" + request.parameters);
 
					return await next?.handle(request);
				}
			}
 
		]/**SCHEMA_HANDLERS*/,

 

Unfortunately it does not seem to work. I added a bunch of "console.log" statements, but they are not triggering either.

 

The weirdest part, is that at some point I was getting the "request.dataSourceName:"  logged in the console, but right now i'm not. I have tried doing a hard refresh + clearing cache in browser, using a private window, etc, to no avail. I don't see any errors in Creatio's javascript editor.

 

Any thoughts on how to address?

Like 0

Like

5 comments

Is the lookup a drop-down or a lookup window? That code works for me for dropdowns but for lookup windows I don’t believe they trigger the same request. 
Ryan

The popup modal window lookups can trigger both the crt.LoadDataRequest (when you use the combobox searching functionality without triggering the full popup window) and also the crt.OpenLookupPageRequest (when you click the magnifying glass on the lookup field and get the full modal popup window). As such, you need to have filtering added to both of these currently, frustratingly. The method for applying the filter is different betweenn the two as well! For crt.OpenLookupPageRequest you can apply the filter to the request like below:

{
	request: "crt.OpenLookupPageRequest",
	handler: async (request, next) => {
		const filter = new sdk.FilterGroup();
		await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "UsrColumn", "Value");
 
		// workaround for filters required in Creatio 8.1.0 and older
		const newFilter = Object.assign({}, filter);
		newFilter.items = filter.items;
 
		request.filtersConfig.filterAttributes.push({
			name: "TestFilter",
			loadOnChange: false
		});
 
		request.filtersConfig.attributesConfig.TestFilter = {
			value: newFilter
		};
	}
}

Ryan Farley,

Gotcha! Its a lookup window. 

 

Thanks for replying.

Harvey Adcock,

 

Thanks! Will give it a shot!

I updated my answer to show it in context of being a handler on a page, hopefully that will help.

Show all comments