web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

filtering Lookup should be clear

(0) ShareShare
ReportReport
Posted on by

  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

I have the same question (0)
  • Tim Dutcher Profile Picture
    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.

  • Community Member Profile Picture
    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);

    }

  • Suggested answer
    Yadnyesh Kuvalekar Profile Picture
    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
    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

  • Verified answer
    Yadnyesh Kuvalekar Profile Picture
    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);

  • Suggested answer
    Community Member Profile Picture
    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

  • Keysersozeey Profile Picture
    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans