Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

filtering Lookup should be clear

Posted on by Microsoft Employee

  I have three lookup's. I have to filter the third lookup based on the above two lookuups data it is working fine.

but if i delete data of second lookup then i have to filter the records based on the first lookup.

Now when first i filter the third lookup based on double lookup filter its working fine but if i am deleting on of the lookup and i am trying to filtering the single lookup filter it is showing Invalid Argument.


plz help me to find out the solution

*This post is locked for comments

  • Keysersozeey Profile Picture
    Keysersozeey 195 on at
    RE: filtering Lookup should be clear

    but what if i need to pass an argument to my presearch, i can't doing it like this Xrm.Page.getControl("new_casetype").addPreSearch(addFilter(param));,, i only can doing it like this Xrm.Page.getControl("new_casetype").addPreSearch(function() { addFilter(param) }); , how can i remove my presearch

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: filtering Lookup should be clear

    Hi Yadnyesh,

    now it is working fine thanks for reply and also ur suggestion is solved my issue

  • Verified answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: filtering Lookup should be clear

    Hi,

    When you are using this statement,

    Xrm.Page.getControl("new_casetype").addPreSearch(function() { addFilter() });

    You are binding anonymous function and hence you are unable to remove it.

    Try below:

    Xrm.Page.getControl("new_casetype").addPreSearch(addFilter);

    Xrm.Page.getControl("new_casetype").removePreSearch(addFilter);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: filtering Lookup should be clear

    Hi,

    Thanks for reply

    but see my code in that i applied for removepresearch filter in single lookup filter function that is not working.

    once i am selecting doublelookup and again i am trying to select single lookup filter at that time it is showing Invalid argument

  • Suggested answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: filtering Lookup should be clear

    Hi,

    You cannot delete the custom filter once added. You will have to remove the presearch event handler and re register the same.

    Refer below:

    msdn.microsoft.com/.../gg334266.aspx

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: filtering Lookup should be clear

    sorry for late reply

    here my code is

    function oncategory_change(){

    debugger;

    if(Xrm.Page.getAttribute("new_category").getValue() == null){

         Xrm.Page.getAttribute("new_casetype").setValue();

         casetype_onload();

         Xrm.Page.getAttribute("new_casesubtype").setValue(null);

     }

      else

     {

           casetype_onchange_filter();

      }

    }

    ////////Double Lookup Filter

    function casetype_onchange() {

       debugger;

       // add the event handler for PreSearch Event

       Xrm.Page.getControl("new_casetype").addPreSearch(function() { addFilter() });

    }

    function addFilter() {

     var categoryIdn = Xrm.Page.getAttribute("new_category").getValue() != null ? Xrm.Page.getAttribute("new_category").getValue()[0].id : null;

     var oemId = Xrm.Page.getAttribute("new_oem").getValue() != null ? Xrm.Page.getAttribute("new_oem").getValue()[0].id : null;  

      //var categoryIdn = categoryId.toUpperCase();

      ar filter = "<filter type='and'><condition attribute='new_category'  operator='eq'  value='" + categoryIdn + "'  /><condition attribute='new_oem'   operator='eq'  value='" + oemId + "' /></filter>";

     Xrm.Page.getControl("new_casetype").addCustomFilter(filter);

    }

    /////////single Lookup Filter

    function casetype_onload(){

    debugger;

    Xrm.Page.getControl("new_casetype").removePreSearch(function() { addFilter() });

    Xrm.Page.getControl("new_casetype").addPreSearch(function() { Filtercasetype() });

    }

    function Filtercasetype(){

      Xrm.Page.getControl("new_casetype").removePreSearch(function() { addFilter() });

      var oemId = Xrm.Page.getAttribute("new_oem").getValue() != null ? Xrm.Page.getAttribute("new_oem").getValue()[0].id : null;  

      var fetch = "<filter type='and'><condition attribute='new_oem' value='"+oemId +"'  operator='eq'/></filter>";

      Xrm.Page.getControl("new_casetype").addCustomFilter(fetch);

    }

  • Tim Dutcher Profile Picture
    Tim Dutcher 2,100 on at
    RE: filtering Lookup should be clear

    You'll need to post your code, otherwise we can only guess as to what's wrong.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans