Question

Important! Dependent Dropdown is not working (v8.3)

Hi Team,

I'm working on Lead mini page that contains 2 lookup fields (Dropdown List): 

  • SBU : lookup field of an Object
  • Product: Page Parameter on Lead Mini Page (Lookup)

Product field is dependent on selected value in SBU field. The Product lookup should be dynamically filtered based on the selected SBU.

Current Flow/Behavior: 

  • Initially, the functionality works fine.
    For example:
    • I select SBU = 'A', and the Product dropdown shows items filtered by SBU 'A'.
  • But when I change the SBU to 'B', the Product dropdown still shows the old items from 'A'.
  • It only updates the Product list after selecting one of the old products (from 'A'), and then the list refreshes to show correct products for 'B'.

Source Code: (Handler Method)
------------------------------------------------------------------------------------------

{
            request: "crt.LoadDataRequest",
            handler: async (request, next) => {
                // Apply filter only for Product Lookup
    
                const sbu = await request.$context.ProductDS_UsrSBU_8s02jhp;
                console.log("LoadDataRequest, SBU-Detail: ", sbu)
                if (request.dataSourceName !== "PageParameters_UsrLookupParameter1_3psya3l_List_DS") {
                    return await next?.handle(request);
                }
        
                if (sbu && sbu?.value) {
                    const filter = new sdk.FilterGroup();
                    await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "UsrSBU", sbu.value);
        
                    // Temporary fix for Creatio DevKit SDK filter bug
                    const newFilter = Object.assign({}, filter);
                    newFilter.items = filter.items;
        
                    // ✅ Ensure request.parameters exists
                    request.parameters = request.parameters || [];
        
                    // ✅ Push filter
                    request.parameters.push({
                        type: "filter",
                        value: newFilter
                    });
                }
        
                // Fetch filtered data
                const result = await next?.handle(request);
                if (result && result.length > 0) {
                    console.log("Filtered products for SBU:", result.rows);
                }
        
                return result;
            }
        },
 
        {
            request: "crt.HandleViewModelAttributeChangeRequest",
            handler: async (request, next) => {
                // Only handle changes to SBU
                // console.log(request.attributeName);
                if (request.attributeName === "ProductDS_UsrSBU_8s02jhp" && !request.silent) {
        
                    const sbu = await request.$context.ProductDS_UsrSBU_8s02jhp;
                    console.log("SBU changed:", sbu);
                    
                   // If SBU not available, Product field is cleared & read-only. 
                    if(sbu && sbu?.value){
                        request.$context.ProductVisibilityInLeadHandOffPage = false;
                    } else{
                        request.$context.ProductVisibilityInLeadHandOffPage = true;
                    }
                    
        
                    // ✅ Clear the selected Product field when SBU changes
                    request.$context.PageParameters_UsrLookupParameter1_3psya3l = null;
                    // ✅ Manually fetch new list of filtered products
                    const loadResult = await request.$context.executeRequest({
                        type: "crt.LoadDataRequest",
                        dataSourceName: "PageParameters_UsrLookupParameter1_3psya3l_List_DS",
                        $context: request.$context
                    });
 
                    if (loadResult && loadResult.rows) {
                        // ✅ Manually assign rows to the list property
                        request.$context.PageParameters_UsrLookupParameter1_3psya3l_list = loadResult.rows;
                        console.log("Updated product list after SBU change:", loadResult.rows);
                    }                
                }
        
                return next?.handle(request);
            }
        }

-------------------------------------------------------------------------------------------

Query: When the SBU is changed, the Product lookup should:

  • Clear/reset the previously selected product.
  • Immediately reload and display products filtered by the newly selected SBU.
Like -1

Like

4 comments

Hi Team,

 

Any Update on this. I need help in resolving this issue

Hi Souresh,

In your current implementation filtering logic for the product lookup based on selected SBU seems to be fine. However the manual step, where you try to assign new values 'by hand' can cause interference with Freedom UI. Can you try to keep the filter in crt.LoadDataRequest and on SBU change, clear the Product list and then call executeRequest to reload Product list. There is some before and after for you: 

 

//AS-IS
// ✅ Manually fetch new list of filtered products
const loadResult = await request.$context.executeRequest({
    type: "crt.LoadDataRequest",
    dataSourceName: "PageParameters_UsrLookupParameter1_3psya3l_List_DS",
    $context: request.$context
});
 
if (loadResult && loadResult.rows) {
    // ✅ Manually assign rows to the list property
    request.$context.PageParameters_UsrLookupParameter1_3psya3l_list = loadResult.rows;
    console.log("Updated product list after SBU change:", loadResult.rows);
}
//TO-BE
await request.$context.executeRequest({
    type: "crt.LoadDataRequest",
    dataSourceName: "PageParameters_UsrLookupParameter1_3psya3l_List_DS",
    $context: request.$context
});

I hope that solves your problem.

Hi Jakub,

Thanks for your response.
It is working initially but still having issues when SBU is changed or removed.


1. When selected SBU is removed --> then Product field & Product list must be empty
Issue: It is still showing product List item of earlier selected SBU

 

 

2. When SBU is changed from 'A' to 'B', then product list must be reloaded or refreshed with the products of SBU B.

Issue: It does not reflect product list immediately, first we have to remove product items of earlier SBU, then it refreshes the list-item with selected SBU's products.

  

Below Providing relevant element code & handler method:

Source Code:
---------------------
 
viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
	{
		"operation": "insert",
		"name": "ComboBox_vreboz3",
		"values": {
			"layoutConfig": {
				"column": 1,
				"colSpan": 1,
				"row": 2,
				"rowSpan": 1
			},
			"type": "crt.ComboBox",
			"label": "$Resources.Strings.PageParameters_UsrLookupParameter1_3psya3l",
			"labelPosition": "above",
			"control": "$PageParameters_UsrLookupParameter1_3psya3l",
			"listActions": [],
			"showValueAsLink": true,
			"controlActions": [],
			"valueDetails": null,
			"mode": "List",
			"visible": true,
			"readonly": "$ProductVisibilityInLeadHandOffPage",
			"placeholder": "",
			"tooltip": "",
			"isSimpleLookup": null,
			"secondaryDisplayValue": null
		},
		"parentName": "MainContainer",
		"propertyName": "items",
		"index": 1
	},
],
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
	{
		"operation": "merge",
		"path": [
			"attributes"
		],
		"values": {
			"ProductVisibilityInLeadHandOffPage": {
				value: false
			},
			"ProductDS_UsrSBU_8s02jhp": {
				"modelConfig": {
					"path": "ProductDS.UsrSBU"
				}
			},
			"PageParameters_UsrLookupParameter1_3psya3l": {
				"modelConfig": {
					"path": "PageParameters.UsrProductToHandoff"
				}
			}
		}
	}
]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "crt.LoadDataRequest",
		handler: async (request, next) => {
			// Apply filter only for Product Lookup
 
			const sbu = await request.$context.ProductDS_UsrSBU_8s02jhp;
			console.log("LoadDataRequest, SBU-Detail: ", sbu);
 
			if (request.dataSourceName !== "PageParameters_UsrLookupParameter1_3psya3l_List_DS") {
				return await next?.handle(request);
			}
 
			if (sbu && sbu?.value) {
				const filter = new sdk.FilterGroup();
				await filter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "UsrSBU", sbu.value);
 
				// Temporary fix for Creatio DevKit SDK filter bug
				const newFilter = Object.assign({}, filter);
				newFilter.items = filter.items;
 
				// ✅ Ensure request.parameters exists
				request.parameters = request.parameters || [];
 
				// ✅ Push filter
				request.parameters.push({
					type: "filter",
					value: newFilter
				});
			}
 
			// Fetch filtered data
			const result = await next?.handle(request);
			if (result && result.length > 0) {
				console.log("Filtered products for SBU:", result.rows);
			}
 
			return result;
		}
	},
	{
		request: "crt.HandleViewModelAttributeChangeRequest",
		handler: async (request, next) => {
			// Only handle changes to SBU
			if (request.attributeName === "ProductDS_UsrSBU_8s02jhp" && !request.silent) {
 
				const sbu = await request.$context.ProductDS_UsrSBU_8s02jhp;
				console.log("SBU changed:", sbu);
 
				// ✅ Clear the selected Product field when SBU changes
				request.$context.PageParameters_UsrLookupParameter1_3psya3l_List_DS = null;					
				request.$context.PageParameters_UsrLookupParameter1_3psya3l = [];
 
				// ✅ Let Creatio reload the lookup list automatically
				await request.$context.executeRequest({
					type: "crt.LoadDataRequest",
					dataSourceName: "PageParameters_UsrLookupParameter1_3psya3l_List_DS",
					$context: request.$context
				});
 
				console.log("Product list refresh requested for new SBU");
			}
 
			return next?.handle(request);
		}
	}
]/**SCHEMA_HANDLERS*/,

 

 

Hi Team,

Any update on this, This is quite urgent.

Show all comments