Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Remove the addPreSearch Filter

I am trying to remove the PreSearch filer and my code is as below. How can I achieve the same?

Xrm.Page.getControl("productid").removePreSearch(function () {
    Object
});

Xrm.Page.getControl("productid").addPreSearch(function () {
    fetchxml2();
});

function fetchxml2() {
    var fetchXml1 = "<filter type='and'>"
    fetchXml1 += "<condition attribute='productid' operator='in' >";
    for (var i = 0; i < Itemid.length; i++) {
        fetchXml1 += "<value>" + Itemid[i] + "</value>";
    }

    fetchXml1 += "</condition>";
    fetchXml1 += "</filter>";
    Xrm.Page.getControl("productid").addCustomFilter(fetchXml1);
    //Xrm.Page.getControl("productid").removePreSearch(fetchXml1);

};
like image 742
user3655914 Avatar asked Jan 09 '23 14:01

user3655914


1 Answers

In order to be able to remove the handler via removePreSearch, avoid using an anonymous function by creating a named function and using that in both addPreSearch and removePreSearch:

function preSearchHandler(){
    fetchxml2();
}

Xrm.Page.getControl("productid").removePreSearch(preSearchHandler);

Xrm.Page.getControl("productid").addPreSearch(preSearchHandler);
like image 82
p e p Avatar answered Jan 18 '23 04:01

p e p