I am trying to pre filter a lookup control in a model driven app based on the selection of a option list control. I have written the below script to be executed on change evented of the option list control to trigger the filtering. I am not receiving any errors but for some reason it is not filtering the lookup.
var Sdk = window.Sdk || {};
// set 'Sdk.setServiceFilter' in the Case form onchange event handler region field
Sdk.setServiceFilter = function (executionContext) {
// get the form context
formContext = executionContext.getFormContext();
//get region field value
var region=formContext.getAttribute("cssp_region").getText();
Xrm.Page.getAttribute("cssp_serviceregion").setValue(region);
if (region != 'global') {
//Prepare Condition for the filter
Sdk.filterServices = function () {
// Only show services where region is like selected region
var ServicesFilter = "<filter type='and'><condition attribute='cssp_regiontext' operator='like' value='%" region "%' /></filter>";
formContext.getControl("cssp_service").addCustomFilter(ServicesFilter, "cssp_service");
}
//Apply filter to the lookup field
formContext.getControl("cssp_service").addPreSearch(Sdk.filterServices);
}
}

Report
All responses (
Answers (