
I have an entity called Source Type, it's a lookup field. It's displayed in Account form, in the form has Department lookup field, when the Department changes, it will call the below code to trigger Source Type filter as follows:
var sourceField = formContext.getControl('org_sourcetype');
sourceField.removePreSearch(filterFn);
sourceField.addPreSearch(filterFn);
var filterFn = function (executionContext) {
var formContext = executionContext.getFormContext();
var filterXml = '<filter type="and"><condition attribute="name" operator="eq" value="Anonymous"/></filter>';
formContext.getControl('org_sourcetype').addCustomFilter(filterXml);
}
it's not working as expected. Could you help me to point out the problem cause it doesn't raise any error?



Primary key is "name"
This function is triggered when Department changes:
function updateFilterByDepartment(executionContext) {
try {
var formContext = executionContext.getFormContext();
var departmentValue = formContext.getAttribute('department').getValue();
if (!departmentValue) {
return;
}
formContext.getAttribute('sourcetype').setValue(null);
var departmentId = departmentValue[0].id;
var sourceField = formContext.getControl('sourcetype');
sourceField.removePreSearch(filterFn);
sourceField.addPreSearch(filterFn);
} catch (e) {
console.log(e);
}
}
*This post is locked for comments
I have the same question (0)