Filtering a lookup in Freedom UI - Help needed

Hi Community, 



Is there anyone who might be able to help me with the code below? I am trying to filter a lookup column, by the value of another lookup column on the same page.

Specifically, my column "PrimaryContact" should be filter Contacts where the "Account" is equal to the "UsrCompanyName" of the same page. 



I've tried many things in the "Value" for rightExpression, but can't seem to get it to work. The rest of the code seems okay because if I add a Guid of an Account to the value, it filters fine. 



Thanks!



 

"LookupAttribute_j53fgnq_List_BusinessRule_Filter": {
					"value": {
						"filterType": 6,
						"isEnabled": true,
						"items": {
							"CustomFilters": {
								"filterType": 6,
								"isEnabled": true,
								"items": {
									"cb855fc4-4526-475a-beea-8e41a7f5a439": {
										"comparisonType": 11,
										"filterType": 1,
										"isEnabled": true,
										"leftExpression": {
											"expressionType": 0,
											"columnPath": "Account"
										},
										"rightExpression": {
											"expressionType": 2,
											"parameter": {
												"dataValueType": 1,
												"value": "$PDS.UsrCompanyName.Id"
											}
										},
										"trimDateTimeParameterToDate": false
									}
								}
							}
						}
					}
				}, 
 

 

Like 2

Like

4 comments
Best reply

Hi Harry,

It would be easier to handle the request for when the lookup requests its data source and then add the filters to that request since you'd have access to page data.

When the lookup is activated (user clicks the dropdown) it sends a crt.LoadDataRequest. You can listen for that and then add the filters there. The request would look something like this: 

handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "crt.LoadDataRequest",
		handler: async (request, next) => {
		    // the data soruce name will be the lookup attribute name + "_List_DS"
			if (request.dataSourceName !== "LookupAttribute_46uzwvy_List_DS") {
				return await next?.handle(request);
			}
 
			// get other page values
			const compId = request.$context.UsrCompanyName.value;
 
			// add filter
			request.parameters.push({
				type: "filter",
				value: {
						"filterType": 6,
						"isEnabled": true,
						"items": {
							"CustomFilters": {
								"filterType": 6,
								"isEnabled": true,
								"items": {
									"cb855fc4-4526-475a-beea-8e41a7f5a439": {
										"comparisonType": 11,
										"filterType": 1,
										"isEnabled": true,
										"leftExpression": {
											"expressionType": 0,
											"columnPath": "Account"
										},
										"rightExpression": {
											"expressionType": 2,
											"parameter": {
												"dataValueType": 1,
												"value": compId
											}
										},
										"trimDateTimeParameterToDate": false
									}
								}
							}
						}
			});
 
			return await next?.handle(request);
		}
	}
]/**SCHEMA_HANDLERS*/,

As a side note, for the filter, I believe something along these lines should work. It's close the working, but the end result request shows in the network tab that the filter key and filter values get added separately to the filters array causing a server error. Hopefully we'll get more details on this sort of thing soon:

(Note, the below doesn't work yet, but sharing it in case someone else gets it to work)

handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "crt.LoadDataRequest",
		handler: async (request, next) => {
		    // data soruce name is lookup attribute + "_List_DS"
			if (request.dataSourceName !== "LookupAttribute_46uzwvy_List_DS") {
				return await next?.handle(request);
			}
 
			let filters = new sdk.FilterGroup();
			filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Type.Name", "Partner");
 
			// add filter
			request.parameters.push({
				type: sdk.ModelParameterType.Filter,
				value: filters
			});
 
			return await next?.handle(request);
		}
	}
]/**SCHEMA_HANDLERS*/,

Ryan

Hi Harry,

 

In case you doubt about the filtration on the column you can create a test list based on the object of your lookup column and specify the needed filtration there:

and

save the page and open the code. As a result you will see an autogenerated code of the working filtration that then can be applied to the column:

HI Oleg, 



Thank you. This example works well when applying a static filter. However, it seems not to work the same when trying to apply filter by page data. 



Do you have any example how to translate this same method so that I can filter a lookup column by page data? 



Thank you 

Hi Harry,

It would be easier to handle the request for when the lookup requests its data source and then add the filters to that request since you'd have access to page data.

When the lookup is activated (user clicks the dropdown) it sends a crt.LoadDataRequest. You can listen for that and then add the filters there. The request would look something like this: 

handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "crt.LoadDataRequest",
		handler: async (request, next) => {
		    // the data soruce name will be the lookup attribute name + "_List_DS"
			if (request.dataSourceName !== "LookupAttribute_46uzwvy_List_DS") {
				return await next?.handle(request);
			}
 
			// get other page values
			const compId = request.$context.UsrCompanyName.value;
 
			// add filter
			request.parameters.push({
				type: "filter",
				value: {
						"filterType": 6,
						"isEnabled": true,
						"items": {
							"CustomFilters": {
								"filterType": 6,
								"isEnabled": true,
								"items": {
									"cb855fc4-4526-475a-beea-8e41a7f5a439": {
										"comparisonType": 11,
										"filterType": 1,
										"isEnabled": true,
										"leftExpression": {
											"expressionType": 0,
											"columnPath": "Account"
										},
										"rightExpression": {
											"expressionType": 2,
											"parameter": {
												"dataValueType": 1,
												"value": compId
											}
										},
										"trimDateTimeParameterToDate": false
									}
								}
							}
						}
			});
 
			return await next?.handle(request);
		}
	}
]/**SCHEMA_HANDLERS*/,

As a side note, for the filter, I believe something along these lines should work. It's close the working, but the end result request shows in the network tab that the filter key and filter values get added separately to the filters array causing a server error. Hopefully we'll get more details on this sort of thing soon:

(Note, the below doesn't work yet, but sharing it in case someone else gets it to work)

handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "crt.LoadDataRequest",
		handler: async (request, next) => {
		    // data soruce name is lookup attribute + "_List_DS"
			if (request.dataSourceName !== "LookupAttribute_46uzwvy_List_DS") {
				return await next?.handle(request);
			}
 
			let filters = new sdk.FilterGroup();
			filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Type.Name", "Partner");
 
			// add filter
			request.parameters.push({
				type: sdk.ModelParameterType.Filter,
				value: filters
			});
 
			return await next?.handle(request);
		}
	}
]/**SCHEMA_HANDLERS*/,

Ryan

Thank you, Ryan. That worked perfectly. 

Show all comments