I have some JS code here that creates a custom filter using some criteria and then adds it to a lookup field on the form. When this code is triggered and ran the first time it works properly; the correct results appear. But if you change the criteria of the custom filter (change one of the fields on the form the createCustomFilter command uses to create the fetchxml), then no results show up in the lookup when there should be results.
This issue only occurs in the new Unified Interface. I have tested this same code in the Web Interface and this issue does not occur; the code runs properly.
My guess is that the previously applied filter is not being removed? That's why no results show up. Is there any workaround that would allow this to work in the UCI?
Please advise.
var filter;
function OnFieldChange(executionContext) {
var formContext = executionContext.getFormContext();
if (filter != "" && filter != null) {
formContext.getControl("test_lookupfield").removePreSearch(lookupCustomFilter);
}
filter = createCustomFilter(executionContext);
formContext.getControl("test_lookupfield").addPreSearch(lookupCustomFilter);
}
function lookupCustomFilter(executionContext) {
var formContext = executionContext.getFormContext();
formContext.getControl("test_lookupfield").addCustomFilter(filter);
}
function createCustomFilter(executionContext) {
//creates a custom fetchxml filter that has been tested and is correct
}
Here's the essence of how we're filtering lookups in both the UCI and Legacy UI in a v9.1 system:
Please note that I adapted this code for simplicity and privacy. I did not test it in its current form.