function filterSubjectOptions(executionContext) {
var formContext = executionContext.getFormContext(); // Get the form context
console.log("Subject field : ", formContext.getControl("subjectid"));
//formContext.getControl("subjectid").addPreSearch(AddSubjectFilter); // not working
formContext.getControl("subjectid").addPreSearch(function() {
AddSubjectFilter(formContext); // Pass formContext directly still not working
});
console.log("PreSearch added to subject lookup."); // Verify that addPreSearch was called
}
function AddSubjectFilter(formContext) {
console.log("CustomFilterFunction triggered");
var caseTypeAttribute = formContext.getAttribute("casetypecode"); // Get the Case Type field
if (!caseTypeAttribute) {
console.error("Case Type attribute is null or undefined.");
return; // Exit if Case Type is not found
}
var caseType = caseTypeAttribute.getValue(); // Get the value of the Case Type
if (caseType == null) {
console.error("Case Type is not selected.");
return;
}
console.log("Case Type selected: ", caseType); // Log the Case Type value
var filterXml = "";
// Apply the filter based on the selected Case Type
if (caseType == 1) { // Case Type: Service Request
filterXml = "<filter type='or'>" +
"<condition attribute='title' operator='eq' value='Increase Usage Limit' />" +
"<condition attribute='title' operator='eq' value='Request Secondary Card' />" +
"</filter>";
}
if (caseType == 2) { // Case Type: Complaint
filterXml = "<filter type='or'>" +
"<condition attribute='title' operator='eq' value='Amount not reimbursed' />" +
"<condition attribute='title' operator='eq' value='Card charges applied incorrectly' />" +
"</filter>";
}
// Apply the custom filter to the Subject lookup field
formContext.getControl("subjectid").addCustomFilter(filterXml,'subject');
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,900 Super User 2024 Season 2
Martin Dráb 229,275 Most Valuable Professional
nmaenpaa 101,156