var formContext = executionContext.getFormContext();
var eventSource = executionContext.getEventSource();
var gridContext = formContext.getControl("OpportunityProductsGrid");
if (eventSource) {
// Get the option set field value
var optionSetValue = gridContext.getAttribute("optionsetfield").getValue();
var lookupControl = gridContext.getControl("lookupfield").getControlType();
if (lookupControl == null) {
console.error("Lookup control not found.");
return;
}
lookupControl.removePreSearch(function () {
addLookupFilter(executionContext);
});
if (optionSetValue === 802050018 || optionSetValue === 802050240 || optionSetValue === 802050091) {
lookupControl.addPreSearch(function () {
addLookupFilter(executionContext);
});
}
else {
// No filter is applied when the option set value differs
lookupControl.removePreSearch(function () {
addLookupFilter(executionContext); // This ensures no filter is applied
});
console.log("No option set value or different value selected, showing all lookup values.");
}
}
}
var formContext = executionContext.getFormContext();
var gridContext = formContext.getControl("OpportunityProductsGrid");
var lookupControl = gridContext.getControl("lookupfield").getControlType();
var optionSetValue = formContext.getAttribute("optionsetfield").getValue();
// FetchXML to filter the lookup values based on the 'market' field
var fetchXML = "<filter type='and'>" +
"<condition attribute='market' operator='eq' value='DACH' />" + // Change 'DACH' as needed
"</filter>";
lookupControl.addCustomFilter(fetchXML, "lookupEntity");
}
else {
// Apply an empty filter to show all records (no actual filtering)
var emptyFilter = "<filter type='and'></filter>";
lookupControl.addCustomFilter(emptyFilter, "lookupEntity");
}
}