How to filter lookup data based on column value (State/Region) in multi-select dropdown

Hi Community,

I’m working on a requirement where I need to filter Region lookup data in a multi‑select dropdown field based on a column value (State/Region).

Basically, when a user opens the lookup field, it should only display the records that match the given State condition.


Here is my viewConfigDiff code:

viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
...
{
				"operation": "insert",
				"name": "MultiSelect_ugo4wdi",
				"values": {
					"layoutConfig": {
						"column": 1,
						"row": 3,
						"colSpan": 2,
						"rowSpan": 1
					},
					"type": "crt.MultiSelect",
					"label": "#ResourceString(MultiSelect_ugo4wdi_label)#",
					"recordId": "$Id",
					"recordRelationColumnName": "ImpAccount",
					"selectSchemaName": "ImpStateInterestMultiselect",
					"selectColumnName": "ImpStateInterestField",
					                          "selectFilter": {
      "items": {
        "filterByRegion": {
          "comparisonType": 3,
          "isEnabled": true,
          "filterType": 1,
          "leftExpression": {
            "expressionType": 0,
            "columnPath": "ImpStateRegion"
          },
          "rightExpression": {
            "expressionType": 2,
            "parameter": {
              "dataValueType": 1,
              "value": "State"
            }
          }
        }
      }
    },
					"visible": true,
					"labelPosition": "above",
					"placeholder": "",
					"tooltip": ""
				},
				"parentName": "GridContainer_qy480gv",
				"propertyName": "items",
				"index": 3
			},
			...
			]/**SCHEMA_VIEW_CONFIG_DIFF*/,

I’ve tried adding filtering logic in the source code, but I’m not getting the expected result. Here is my handler code:

handlers: /**SCHEMA_HANDLERS*/[
			{
  request: "crt.LoadDataRequest",
  handler: async (request, next) => {
    // Ensure this runs only for your MultiSelect list data source
	    console.log("Current DataSourceName:", request.dataSourceName);
	   console.log("EntitySchema:", request.entitySchemaName);
 
    // Ensure it's the right source + schema
 
    if (request.dataSourceName !== "MultiSelect_ugo4wdi_List_DS") {
		console.log("Hello I am in a log box 1234");
      return await next?.handle(request);
    }
 
    const filter = new sdk.FilterGroup();
 
    // Filter where ImpStateRegion == 'State'
    await filter.addSchemaColumnFilterWithParameter(
      sdk.ComparisonType.Equal,
      "ImpStateRegion", // <-- Column in ImpStateInterestMultiselect to filter on
      "State"           // <-- The fixed value to filter by
    );
 
    // Workaround for Creatio DevKit filter bug
    const newFilter = Object.assign({}, filter);
	  console.log("Hello I am in a log box");
    newFilter.items = filter.items;
 
    // Add filter to request parameters
    request.parameters.push({
      type: "filter",
      value: newFilter
    });
 
    // Proceed with next handler
    return await next?.handle(request);
  }
}
 
		]/**SCHEMA_HANDLERS*/,

I’ve also attached a screenshot of the current setup.

Multiselect filter

Multiselect element code

Can someone guide me on how to correctly apply filters for a multi‑select lookup field?
Do I need to configure this through the business rules, or is filtering only possible via overriding the source code handler?

Any help or examples would be greatly appreciated!

Thanks in advance.

Like 0

Like

1 comments

Hello,

To set up filtering for lookup fields in the dropdown, you’ll need to add a new business rule.

Please follow these steps:

  1. Open the Business Rules section on the current form page.
  2. Click "+ Add rule" under the Account business rules.
  3. In the "Then" block, select the action "Apply filter". Leave the "If" block empty.
  4. Configure the filter as follows:

Filter Region by State Where Region.State = Account.State

Save your changes.

Show all comments