Add filter to a lookup RRS feed

  • Question

  • We have a custom entity has some 14 fields that need by the user. Before crm the users were Excel to run there filters to narrow down the data they were looking for in the sheet.  After CRM they want to be able to see all those 14 entries in the lookup view (this is done) but what they want to do is to be able to filter the data before clicking the lookup button on the form. As for now they like t have filters based on state, N,S,E,W of the state, town etc. I still need to figure out if these filters should be on the main form or the lookup window should open and then the filters are added and the lookup view gets refreshed. 

    Any pointers will be greatly appreciated. 

    Thank you


    Wednesday, May 5, 2010 7:23 AM


All replies

  • try this


    Tiaan van Niekerk http://crmdelacreme.blogspot.com Skype:tiaan.van.niekerk1
    Wednesday, May 5, 2010 7:39 AM
  • Syed,

      One easy option is to use the additionalparam form field to auto-populate the search for a lookup. Here is the the article I used to implement similar functionality.



     Another option would be to use fetchxml. I posted a slightly modified version of one originally developed by Daniel Cai. This example converts a lookup to a drop-down and filters it with a fetch filter.




      Hope this helps!

    Chris Wigley MCAD\MCPD
    Wednesday, May 5, 2010 5:04 PM
  • Thank you Tiaan, Chris for your response. All three solutions seem to do the work, Daniel Cai solutions comes closet to what I am looking for,but the question is in my case is that there are nearly 10 different data values on which the filer may or may not be applied. So can Daniel's code be used.

    I my client looks for a school via a lookup, the lookup output shows nearly 1000 schools, the client has 10 different filters (year, location,state and etc) that may or may not be applied. 

    I hope this question makes some sense.

    Thank you

    Friday, May 7, 2010 7:50 AM
  • After looking through the solution and my requirement I have come up with an idea that would help me get the desired results and for that I need some input from you all. Actually this lookup I have mentioned above will be present on quote form where the user will click on the lookup so that to find a school from the list by filtering the search. I was thinking to introduce the filter there should be a small window that should pop-up after clicking the lookup, on this window I can have all the 14 filters and based on the chosen filters the user again clicks on a button on this form to get the actual output of the lookup result. 

    Let me know if any of you guys think this idea makes sense and if there are any solutions for it.

    Thank you



    Monday, May 10, 2010 4:34 PM
  • I have recently asked a similar question but I am still stuck how to go about the problem. My lack of experience with fetchXML is one of the reason I am having hard time getting to my solution. Here is my problem, I have a lookup on quote form, along with this lookup there are couple of text fields on the same form. These text fields will act as a filter to the lookup below. For example when the text fields will have any of the following entered last name, first name, ____,state and nationality then the lookup should give an output based on this condition. If last name is David then the lookup view should only have all the records of the individuals whose last name is David and the output should be different if all the text fields have the required information. If I am using the following fetchxml code then I like to know how can I make my lookup do a search based on the values and make sure that this data is shown in the lookup view.



    <fetch mapping="logical" count="50">
    <entity name="contact">
    <attribute name="contactid" />
    <attribute name="emailaddress1" />
    <attribute name="firstname" />
    <attribute name="jobtitle" />
    <attribute name="lastname" />
    <attribute name="mobilephone" />
    <attribute name="parentcustomerid" />
    <attribute name="telephone1" />
    <condition attribute="parentcustomerid" operator="eq" value="94bf630f-b364-de11-8f1d-001cc02e75b4" />
    Wednesday, May 12, 2010 2:44 PM
  • Following is the code that I added on onChange of my lookup.


    var field = crmForm.all.new_schoolid; 
    if(crmForm.ObjectId == null) 
        // Disable lookup for new account record as there can be no contacts 
        field.Disabled = true; 
         // Ensure that search box is not visible in a lookup dialog
        field.lookupbrowse = 1; 
        // Pass fetch xml through search value parameter 
         "<fetch mapping='logical'><entity name='new_school'>" 
        + "<filter><filter type='and'><condition attribute='new_units' operator='eq' value='" 
        + crmForm.ObjectId 
        + "' /></filter></entity></fetch>"); 

    This code actually is from this link:


    I also added code in my lookupsingle.aspx from the above link.

    The problem I have is that when I enter a number for the unit an click on the school lookup I get the same result (lookup window) as when I don't enter any number for the unit.

    Correct me if I am wrong, my understanding of the proposed solution is suppose to go and check and value entered for the unit and then submit the result in the lookup view form.

    Any help will be appreciated.


    Wednesday, May 12, 2010 2:58 PM