I require some coding help with removing a presearchfilter that has applied, if the other field has changed.

So there is the "subjectid" lookup control, which you select the parent subject, then the "int_category" is filtered to show only the children of the selected subject.

Currently the code works, unless you change the subject, the lookup values in the category's still shows the previous filtered values.

Current code is below, and the on change event for subjectid control runs filterCaseCategory

function filterCaseCategory() {

function addCategoryilter() {
  if (Xrm.Page.data.entity.attributes.get("subjectid").getValue() != null) {
    var subjectvalue = Xrm.Page.getAttribute("subjectid").getValue()[0].id;
    var subjectvalueguid = subjectvalue.substring(1, subjectvalue.length - 1);
    var CategoryFilter = "<filter type='or'><condition attribute='parentsubject' operator='eq' value='" + subjectvalueguid + "' /><condition attribute='subjectid' operator='eq' value='" + subjectvalueguid + "' /></filter>";
    Xrm.Page.getControl("int_category").addCustomFilter(CategoryFilter, "subject");