I am required to update the case quick create form so users enter a category [subjectid (lookup to the subject entity) and a subcategory [cb_subcategory (also a lookup to the subject entity). When a user enters a category [subject I'd like to dynamically filter the lookup on the subcategory field [cb_subcategory. It should only be possible to select subjects where the parent subject is the category. If a user changes the category field then the subcategory should be empty.
When a user enters a category [subjectid the JavaScript below successfully adds a filter to the subcategory field. On change of subject the subcategory field [cb_subcategory successfully updates to null but the subcategory lookup filter is not updated. What am I doing wrong?
function setSubjectsFilter(executionContext) { formContext = executionContext.getFormContext(); formContext.getAttribute("cb_subcategory").setValue(null); formContext.getControl("cb_subcategory").addPreSearch(filterSubCategory); debugger; } function filterSubCategory(){ var parentSubject = (formContext.getAttribute("subjectid").getValue()[0].id).replace("{", "").replace("}", ""); debugger; var fetchXML = "" "" "" "" "" "" "" ""; console.log(fetchXML); debugger; var layoutXML = "" " " " " " " " "; var viewID = "00000000-0000-0000-0000-000000000010"; var viewDisplayName = "SubCategories"; if(parentSubject != null) { formContext.getControl("cb_subcategory").addCustomView(viewID, "subject",viewDisplayName, fetchXML, layoutXML, true); } else{ formContext.getControl("cb_subcategory").setVisible(false); } }