locked
Filtered Lookup Lists in CRM4 RRS feed

  • Question

  •  

    Hi,

     

    In CRM 3 I used to be able to filter the contents of a second lookup list based on my selection of a 'parent' lookup list. This was achieved via the use of fetchXML

     

    For example say the first entity was a list of books and the second contained the list of chapters for these books. When I selected the book in the first lookup this limits the options in the second lookup to just htose chapters for the book selected in list 1.

     

    I usd a variation of the code shown below to achiev this

     

    //----------------------------------------------------------------------------------------------

    setClassificationLookups = function() {

    // Filter Classification L2 based on Classification L1

    //----------------------------------------------------------------------------------------------

     

      if( crmForm.all.new_classificationl1id.DataValue != null ) {

        var entityForList = "new_caseclassificationlevel2";

        var attribForFilter = "new_classificationl1id" ;

        var idToFetch = crmForm.all.new_classificationl1id.DataValue[0].id+ "" ;

        var fetchStr =  "<fetch mapping='logical'>" +

                            "  <entity name='" + entityForList + "'>" +

                            "    <all-attributes />" +

                            "    <filter>" +

                            "      <condition attribute='" + attribForFilter + "' operator='eq' value='" + idToFetch + "' />" +

                            "    </filter>" +

                            "  </entity>" +

                            "</fetch> ";

     

        crmForm.all.new_classificationl2id.lookupbrowse = 1; 

        crmForm.all.new_classificationl2id.AddParam("fetchXml", fetchStr);

         crmForm.all.new_classificationl2id.setAttribute("readonly", false);

     } else { 

      //classification 1 is null

      crmForm.all.new_classificationl2id.setAttribute("readonly", true);

      }

    };

     

    With CRM4 this no longer works. It results in an error telling me to ask the dev community :-)

     

    Has anyone found a way of making this work again? It was a really, really, really useful thing to be able to do and one that SHOULD be in the standard product (the realationshps between the entities are definied etc).

     

    Regards & Thanks

    Rob

     

     

     

    Tuesday, February 5, 2008 12:18 AM

Answers

  •  

    Hi.

     

    Do you still get an error if you use:

    crmForm.all.new_classificationl2id.additionalparams = "search=" + fetchStr;

    Instead of:

    crmForm.all.new_classificationl2id.AddParam("search", fetchStr);

     

    if so:

    I advise constructing the fetch again.

     

    Here is s small tip for getting the right fetch in a snap.

     

    1.  Open advanced find and then press control + N to open it in a fresh window.

    2.  Construct the fetch for new_classificationlevel2  and run it.

    3.  In the results view enter this js into the address bar.

         Javascript:void( alert( document.getElementsByName("fetchxml")[0].value ))

    4.  Press Enter.

     

    This will alert your fetch.

    Now focus the alert dialog and press Ctrl A + Ctrl C to copy it.

    Use this fresh validated fetch in your code.

     

    Adi

     

    Monday, February 11, 2008 8:06 AM

All replies

  • As far as I know there is no way to get this to work in CRM 4; I'll post an update if I find a way to do this. I completely agree that this functionality should be available in a supported way (it should be noted that the method used in CRM 3, using the additionalParam, was never supported, so MS were under no obligation to maintain it in CRM 4)

     

    Tuesday, February 5, 2008 10:39 PM
    Moderator
  • Changed the JS binding code to:

     

    crmForm.new_lookupLeaf.lookupbrowse = 1

    crmForm.new_lookupLeaf.additionalparams = "search=<fetch version="…></fetch>";

     

    In the CRMWeb\_controls\lookup\lookupsingle.aspx wrote this Server Side code at the top of the page.

     

    <script runat="server">

     

    protected override void OnLoad(EventArgs e)

    {

         base.OnLoad(e);

         crmGrid.PreRender += new EventHandler(crmGrid_PreRender);

    }

     

    void crmGrid_PreRender(object sender, EventArgs e)

    {

         if( Request["search"] + "" != "" && Request["browse"] + "" == "1" )

         {

               crmGrid.AddParameter("fetchxml", Request["search"] );

               crmGrid.Parameters.Remove("searchvalue");

         }

    }

     

    </script>

     

    That's it

     

     

    • Proposed as answer by Kashif Altaf Thursday, September 30, 2010 3:15 PM
    Friday, February 8, 2008 11:21 AM
  • Thanks heaps for sharing this. I am still a bit confused though...

     

    Your code shows the line  "search=<fetch version="…></fetch>";

     

    I am not sure what should go in the version section. I don't have this in my previous code etc.

     

    Is the field you are using to test this called new_lookupLeaf ?

     

    Would you be able to post a whole working example. That would really help.

     

    I really appreciate your sharing this.

     

    Thanks

    Rob

     

    Sunday, February 10, 2008 9:43 PM
  • Hi Rob.

     

    This is the complete example.

    Here, I'll implement the solution using your code.

     

    Code Snippet

     

    setClassificationLookups = function()

    {

     

        if( crmForm.all.new_classificationl1id.DataValue != null )

         {

                var entityForList = "new_caseclassificationlevel2";

                var attribForFilter = "new_classificationl1id" ;

                var idToFetch = crmForm.all.new_classificationl1id.DataValue[0].id+ "" ;

                var fetchStr =         "<fetch mapping='logical'>" +

                                               "  <entity name='" + entityForList + "'>" +

                                               "    <all-attributes />" +

                                               "    <filter>" +

                                               "      <condition attribute='" + attribForFilter + "' operator='eq' value='"+ idToFetch + "' />" +

                                   "    </filter>" +

                                   "  </entity>" +

                                   "</fetch> ";

     

                crmForm.all.new_classificationl2id.lookupbrowse = 1; 

                crmForm.all.new_classificationl2id.AddParam("search", fetchStr);

                /*

                            My line is the result of using AddParam.

                            crmForm.all.new_classificationl2id.additionalparams = "search=" + fetchStr;

                */

    crmForm.all.new_classificationl2id.setAttribute("readonly", false);

     }

     else

     { 

                //classification 1 is null

                crmForm.all.new_classificationl2id.setAttribute("readonly", true);

      }

    };

     

     

     

    Now take the server side code and put it in singlelookup.aspx at the top of the page and your are done.

                My fetch uses version because this is the default attribute on the fetch tag, it is not mandatory and you can 

                omit it if you like.

     

                * If the AddParam function does not work simply use my line.

               

    Cheers,

    Adi

     

     

    Sunday, February 10, 2008 10:50 PM
  • Thanks so much for following this through. Much appreciated.

     

    It now contrusts the fetch and I don't get any errors until I press the lookup button for the second category. When I do this I get the error

     

    "To use this saved view you must remove criteria and columns that refer to deleted or non searchable items."

     

    I have checked and all the fields are searchable and I have gone though and triple checked field names etc also. I have added new_classificationlevel1 to the lookup view but no change. I have also restarted IIS.

     

    Do you know why I would be getting this?

     

    Regards

    Rob

     

    Monday, February 11, 2008 12:58 AM
  •  

    Hi.

     

    Do you still get an error if you use:

    crmForm.all.new_classificationl2id.additionalparams = "search=" + fetchStr;

    Instead of:

    crmForm.all.new_classificationl2id.AddParam("search", fetchStr);

     

    if so:

    I advise constructing the fetch again.

     

    Here is s small tip for getting the right fetch in a snap.

     

    1.  Open advanced find and then press control + N to open it in a fresh window.

    2.  Construct the fetch for new_classificationlevel2  and run it.

    3.  In the results view enter this js into the address bar.

         Javascript:void( alert( document.getElementsByName("fetchxml")[0].value ))

    4.  Press Enter.

     

    This will alert your fetch.

    Now focus the alert dialog and press Ctrl A + Ctrl C to copy it.

    Use this fresh validated fetch in your code.

     

    Adi

     

    Monday, February 11, 2008 8:06 AM
  • Thank you!!!!

     

    The previous fetch construction worked fine in R3 but doesn't work in R4. The two strings look quite different. Your method for getting the fetch string is one that I had forgotten about. Thanks heaps.

     

    This is all now working which is fantastic.

     

    Thanks again! Legend!

     

    Regards

    Rob

    Monday, February 11, 2008 10:28 PM
  • Hi Adi,

     

    Is there any other way to use fetchxml as you've suggested that doesn't involve editing the MSCRM lookupsingle.aspx page on the server? And with as little development as possible.

    I'm looking for something that is going to be supported...

     

    Thanks,

    Claire.

     

    Tuesday, February 26, 2008 1:28 PM
  • Hi.

     

    Yes there is a way, I can think of 2 actually, but they are too expensive and time consuming.

    You can refer your customer to stunnware.com, he has built a supported solution for this absence of valuable functionality.

     

    Adi

     

    Tuesday, February 26, 2008 2:15 PM
  • Hi,

     

    Does adding/removing parameters like "fetchxml" and "searchvalue" introduce problems with other lookup controls? I really need to be sure it is safe code I can use.

     

    Best regards,

    Merijn

    Wednesday, February 27, 2008 4:45 PM
  • Hi.

     

    The fixed is an extension to the already known, undocumented and unsupported workaround used in v3.0.

    The only difference is that in v3.0 the lookupsingle.aspx accepted the fetchxml query string parameter and passed the value to the CRM Grid.

     

    In v4.0 the fetchxml parameter is forbidden for use. This is also true if you use other unknown parameters.

    In order to get around that you need to use a supported parameter that accepts xml such as the search parameter and you need to pass the value to the CRM Grid your self.

     

    This type of fix can not be implemented in the multi lookup because it does not use a CRM Grid.

     

    I suggest keeping a record of all unsupported changes you make. There are no guaranties that this fix will hold water in all occasions. You should know your code and understand what it does before you use it.

     

    Cheers,

    Adi 

     

    Saturday, March 1, 2008 11:25 PM
  • Hello Adi,

    I am trying to find a way to filter the list I get from a lookup dialog when I am adding existing records (of a custom entity - c1) to another, related, custom entity, c2 (CRM 4.0).

    I saw your example and I was wondering if such of a method can be applied in this case, and, does the scripting need to be added on the onload event of c2?

    Thank you.
    Tuesday, April 8, 2008 1:04 PM
  • Hi

     

    If c2 has a c1 lookup then yes. Apply the c2 with the onload script mentioned above.

    You also need to change the lookupsingle.aspx page to apply filtering.

     

    Cheers,

    Adi

     

     

    Wednesday, April 9, 2008 2:05 AM
  • Hi, and thanks for replying.

    c2 does not have a lookup field for c1. I was trying to point the fact that the lookup adds existing records of c1 into the related view from c2. There is a n-to-n relationship between those two, so that I'm not using the c2's form fields, but a link from the left panel is opening the view of the c1 records related to c2.

    That's why I set add existing in italics in the post above. It's that toolbar option from c1's view.

    I hope I made sense in my explanation.

    Also, I saw that the 'external' view for c1-s is somekind of an IFrame.. does this mean that I can access it using some URL?

    Thank you,
    Florin
    Wednesday, April 9, 2008 6:29 AM
  •  

    I have tried the method above as well as modifying lookupsingle.aspx.  While I do not receive an error, the results are not filtered either.  In my case, I am filtering a user lookup field based upon role.  I am using the fetchXml below which works fine when I paste it into FetchXML Builder:

     

    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>

      <entity name='systemuser'>

        <attribute name='systemuserid'/>

        <link-entity name='systemuserroles' from='systemuserid' to='systemuserid' visible='false' intersect='true'>

          <link-entity name='role' from='roleid' to='roleid' alias='aa'>

            <filter type='and'>

              <condition attribute='name' operator='eq' value='Investigator'/>

            </filter>

          </link-entity>

        </link-entity>

      </entity>

    </fetch>

     

    Which returns:

     

    <resultset morerecords='0'>
     <result>
      <systemuserid>{D0E378BE-8C0C-DD11-8977-0003FF632A23}</systemuserid>
     </result>

    </resultset>

     

    As it should since I only have one user assigned to the role I am querying for.  Also, here is my javascript:

     

    var search = "<fetch mapping='logical'><entity name='systemuser'><attribute name='systemuserid'/><link-entity name='systemuserroles' from='systemuserid' to='systemuserid' visible='false' intersect='true'><link-entity name='role' from='roleid' to='roleid' alias='aa'><filter type='and'><condition attribute='name' operator='eq' value='Investigator'/></filter></link-entity></link-entity></entity></fetch>"

     

    crmForm.all.new_leadcaseagentid.lookupbrowse = 1;
    crmForm.all.new_leadcaseagentid.AddParam("search", search);

     

    Thanks in advance.

    Thursday, April 17, 2008 4:00 PM
  • Hi.

     

    The lookupsingle.aspx code has a typo in the condition:

     

    void crmGrid_PreRender(object sender, EventArgs e)

    {

         /* if( Request["search"] + "" != "" && Request["borwse"] + "" == "1" ) */

         if( Request["search"] + "" != "" && Request["browse"] + "" == "1" )

         {

               crmGrid.AddParameter("fetchxml", Request["search"] );

               crmGrid.Parameters.Remove("searchvalue");

         }

    }

     

    Try it now...

     

    Adi

     

    Thursday, April 17, 2008 7:04 PM
  •  

    awesome, thanks!
    Thursday, April 17, 2008 7:33 PM
  • I'm not getting any filtering.  I think I have it correct, I added the most recent version of the lookupsingle code to the very top of the page and am using the following javascript:

     

    var search = "<fetch mapping='logical'><entity name='account'><filter type='and'><condition attribute='customertypecode' operator='eq' value='9'/></filter></entity></fetch>"

    crmForm.all.new_mglerhusid.lookupbrowse = 1;
    crmForm.all.new_mglerhusid.AddParam("search", search);

     

    also tried:

     

    crmForm.all.new_mglerhusid.additionalparams = "search=" + search;

     

    and this fetch:

     

    var search = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='account'><filter type='and'><condition attribute='customertypecode' operator='eq' value='9'/></filter></entity></fetch>"

     

     

    Friday, April 18, 2008 12:19 AM
  •  

    Hi All,

     

    I have implemented a similar kind of functionality in my current development project on MIcrosoft CRM 4.0.

    It is really simple guys.....

    we need not write a complicated code for filtered loookups now.....

    It is easy....

    Just write this code on the first looup button's on change event..

     

     

    var lookupItem = new Array;

    lookupItem = crmForm.all.new_lookup1.DataValue;

    alert(lookupItem[0].id);

    alert(lookupItem[0].name);

    var searchVal = lookupItem[0].name;

     

    crmForm.all.new_lookup2.additionalparams = 'search=' + searchVal.replace("&","%26").replace("+","%2b");

     

     

    This does the job guys......

     

    Happy Coding......

     

    CapriS

    Friday, April 18, 2008 4:17 AM
  •  

    I must have had something wrong wih the lookupsingle ASP, repasted the code and it's working now.

     

    Thanks for posting this solution!

    Friday, April 18, 2008 9:02 AM
  • Hi Adi,

     

    Great - this solved a number of issues I had. One is left in this context:

    From the Product lookup on OpportunityProduct I would like only to display Products, which are in the pricelist selected for the opportunity, i.e. in SQL:

     

    select * from product p

    inner join PricelistItem pi on p.productid = pi.productid

    inner join PriceList pl on pl.pricelevelid = pi.pricelevelid

    where pi.name = <whatever pricelist is on opportunity>;

     

    No good idea of how to do that using the approach described using the fetch command, so any help is appreciated.

     

    Thanks,

    Per

     

    Friday, May 2, 2008 1:49 AM
  •  

    Hi,

     

    Which version of CRm are you working on currently???

    You need to read the price list value from the parent form and then add javascript on the on load event of the form

    to create the filtered product lookup.

     

     

    CapriS

    Friday, May 2, 2008 5:16 AM
  • Code below is not working for CRM 4. Can anyone help

     

     

    function onLoad

    {

     

    //Step 1.Fetch  filtered records
    var entityForList = "account";
    var attribForFilter = "customertypecode";
    var idToFetch = "3";

    var fetchStr= "<fetch mapping= 'logical'>" +
    "<entity name='" + entityForList + "'>" +
    "<all-attributes />" +
    "<filter>" +
    "<condition attribute='" + attribForFilter + "' operator='eq' value='"+ idToFetch + "' />" +
    " </filter>" +
    " </entity>" +
    "</fetch>";
    //Step 2.Send Query to the Lookup
    crmForm.all.new_customerid.lookupbrowse = 1;
    crmForm.all.new_customerid.additionalparams= "search=" + fetchStr;
    crmForm.all.new_customerid.setAttribute("readonly",false);

     

    }

     

    Saturday, May 3, 2008 4:01 AM
  • Hi,

     

    Thanks for the code, it works very good. I want to set a default value in the lookup and i want to get this value from the fields that I have filtered.  Has anyone found a way to do it?

     

    Regards.

    Juanjo

    Thursday, June 12, 2008 11:20 AM
  • If you do it like below and do the check/replace for Ampersands it wont break whenever it encouters an ampersand in your source.  Since you are passing the search attribute via querystring and all, ampersands are not your friend. Smile 

     

    document.FilterLookup = function(source, target)

    {

        if (IsNull(source) || IsNull(target)) { return; }

        var name = IsNull(source.DataValue) ? '' : source.DataValue[0].name;

    while(name.search('&') != -1)

    {

       name= name.replace('&', '%26');

    }

        target.additionalparams = 'search=' + name;

    }

     

     

    document.FilterLookup(crmForm.all.sourcelookupid, crmForm.all.targetlookupid);

     

     

    Jamie

     

    Thursday, June 19, 2008 1:41 PM
    Moderator
  • Instead of this :

     

    while(name.search('&') != -1)

    {

       name= name.replace('&', '%26');

    }

        target.additionalparams = 'search=' + name;

    }

     

    use this :

     

     name=encodeURIComponent(name);

     

     

    It will transform international characters also, and any other strange characters which the user might use.

     

    Kay

    Monday, July 7, 2008 10:39 PM
  • Hi thanks a lot for your great solution,i'm new and i'was look for something like this,, many thanks again

    Saturday, August 9, 2008 12:58 AM
  • Hi,

    I am trying to use your code (very short) to enable filtered lookup.

    I use the lookup1 for the onchange of parentcustomerid, but is the lookup2 used for?

    It is supposed to be on the safe form? for what attribute?

    Can you give example of two entities you used this for?

    You don't use any .aspx file?

    Thanks

    Tuesday, September 16, 2008 8:49 AM
  •  

    Hi,

    I put the runat at server part in the aspx and change the onload script as noted in the previous posts and got

    no change in the results.

     

    Can you give an example of the usage of entities and attributes of which you assigned values in the

    onLoad for these lookups? (for what purpose/situation exactly did you use it)?

     

    I have a 'case' with lookup to 'account' and then lookup to products of the customer (custom entity).

     

    In the code example above does this apply  to the following:

    new_classificationl1id=... the customerid (used in the 'case' form)

    new_classificationl2id= ... the name of the products lookup attribute as used in the 'case' form

    new_caseclassificationlevel2=... the name of the custom entity of the products?

     

    Thanks a lot

     

    Tuesday, September 23, 2008 12:53 PM
  • Adi Katz said:

     I advise constructing the fetch again.

    Here is s small tip for getting the right fetch in a snap.

    1.  Open advanced find and then press control + N to open it in a fresh window.

    2.  Construct the fetch for new_classificationlevel2  and run it.

    3.  In the results view enter this js into the address bar.

         Javascript:void( alert( document.getElementsByName("fetchxml")[0].value ))

    4.  Press Enter.

    This will alert your fetch.

    Now focus the alert dialog and press Ctrl A + Ctrl C to copy it.

    Use this fresh validated fetch in your code.


    Note that there's another trick you can do to get this in a way that you can copy and paste, and that's also pretty convienient for doing other page debugging. You need to have debugging of scripts enabled in your browser and a debugging tool installed (Visual Studio, e.g.), then instead of this:
    Javascript:void( alert( document.getElementsByName("fetchxml")[0].value ))

    You put this in the address bar:
    javascript:debugger

    Then in the debugger, go to the watch window, and put this in the watch list:
    document.getElementsByName("fetchxml")[0].value

    ..and there you go, a value you can copy and paste (and the ability to dissect any part of the javascript DOM because you're now debugging the page).

    By the way for those who are worried about "unsupported changes", I don;t know how many of you ran in to problem with your upgrade from R3 to R4 for the things that were originally done as "Supported" customizations in R3. We ran into quite a few problems and things that had to be completely reworked. Ever since then I've stopped jumping through hoops to do things in a "supported" way. I'd rather have something that's clean and easy to install and then deal with the fact that it's unsupported when R5 comes out - since I'm sure we'll have to rework a lot of the supported customizations for R5 as well!

    Cheers,
    CList

    Friday, March 6, 2009 5:04 PM
  • Hi Adi,

    Thanks for the workaround. I tried your approach and its working perfectly except for the "New" button on the lookup dialog.I request you to please suggest how to retain "New" button functionality on the lookup dialog.

    Thanks.

    Saturday, April 11, 2009 2:37 PM
  • You need to hide the new button. take a look at george's post.
    http://crm.georged.id.au/post/2008/02/16/Filtering-lookup-data-in-CRM-4.aspx

    http://mscrm4ever.blogspot.com/
    Saturday, April 11, 2009 4:10 PM
  • Hi Adi,

    Yes , i tried it. But we have a requirement to enable new buttons for Lookup dialogues. This is important and critical. Hope you can help me.

    Along with that is it possible to enable search option as well ?

    Thanks in Advance !!!
    Saturday, April 11, 2009 4:23 PM
  • About the New Button:

    If you add the following JS lines to you onload event then the new button will open a new instance in the parent context

    //Taken from George’s blog
    
    var field = crmForm.all.primarycontactid; 
    
    if(crmForm.ObjectId == null) 
    
    { 
    
        // Disable lookup for new account record as there can be no contacts 
    
        field.Disabled = true; 
    
    } 
    
    else 
    
    { 
    
        // Ensure that search box is not visible in a lookup dialog
    
        field.lookupbrowse = 1; 
    
        // Support New Button 
    
        field.AddParam("parentId",crmForm.ObjectId); 
    
        field.AddParam("parentType",crmForm.ObjectTypeCode);
    
        // Pass fetch xml through search value parameter 
    
        field.AddParam("search", "<fetch mapping='logical'><entity name='contact'>" 
    
        + "<filter><condition attribute='parentcustomerid' operator='eq' value='" 
    
        + crmForm.ObjectId 
    
        + "' /></filter></entity></fetch>"); 
    
    } 
    
    

    You should also remove the server side code that hides the new button:
    //this._showNewButton = false;

    About the search option:
    This would only make sense if you integrate the search value into the initial fetchxml by adding a search condition.
    The reason that the lookupbrowse equals 1 is to hide the search box that contains the fetchxml (not a pretty sight)


    --------------------------------------------------------------------------------
    http://mscrm4ever.blogspot.com/

     

    • Proposed as answer by CRM Learner Sunday, April 12, 2009 5:18 AM
    • Edited by Adi Katz Sunday, April 12, 2009 8:50 AM
    Saturday, April 11, 2009 10:22 PM
  • Thanks Adi,

    Yes the new button issue was solved with parentid and parenttype parameters. Thanks again for the quick response.
    Sunday, April 12, 2009 5:22 AM
  • Hi,
    Thanks to you   I have the filtered lookup working.
    Users request that whenever they select "x" the associated "y" will be automatically inserted on the (filtered) lookup.
    How this is done?

    Thanks a lot
    Thursday, August 27, 2009 11:42 AM
  • For all those that are as lazy as I am!

    Javascript:void(window.clipboardData.setData('text',document.getElementsByName("fetchxml")[0].value));
    Tuesday, September 22, 2009 8:55 AM
  • I got this working for another form but for some reason on the current form im working on it wont work...the second lookup box shows no results.

    I have 2 custom entities linked to each other (Simulator and Kit). I did an advance find and got the result i wanted and constructed my fetch.

    Following code:

    if(crmForm.all.new_simulatorid.DataValue != null) 
    {
      var SimulatorFilter = crmForm.all.new_simulatorid.DataValue[0].id;
      var fetchStr = "search=<fetch mapping='logical'> " +
    	" <entity name='new_conversionkit'> " +
            "  <all-attributes />" +
    	"  <order attribute='new_name' descending='false'/> " +
    	"  <link-entity name='new_simulator' from='new_simulatorid' to='new_simulatorid' alias='aa'> " +
    	"    <filter type='and'> " +
    	"     <condition attribute='new_simnumber' operator='eq' value='" + SimulatorFilter + "'/> " +
    	"    </filter> " +
    	"  </link-entity> " +
    	" </entity> " +
    	"</fetch> ";
    
      crmForm.all.new_kitusedid.lookupbrowse = 1;  
      crmForm.all.new_kitusedid.additionalparams=fetchStr;
      crmForm.all.new_kitusedid.setAttribute("readonly", false);
      crmForm.all.new_kitusedid.DataValue = null;
    } 
    else 
    {  
      //Simulator is null 
      crmForm.all.new_simulatorid.setAttribute("readonly", true);
    }
    

    When i select the simulator in the first lookup box (new_simulatorid) i checked and a guid is being assigned to the variable.
    Now when i click the second lookup box (new_kitusedid) it shows no results. However the query i tested with advance find shows results.

    Can anybody see anything wrong in the code?
     
    Tuesday, February 2, 2010 2:29 PM
  • what you also at take a look at is the pseudo filtered lookup for CRM from Jim Wang
    Tiaan van Niekerk http://crmdelacreme.blogspot.com Skype:tiaan.van.niekerk1
    Wednesday, February 3, 2010 5:46 AM
  • My fetch query was incorrect. Working now. Thanks anyways.

    Wednesday, February 3, 2010 5:24 PM
  • Try Prompt to make copying easy!

    prompt("Copy this Value instead",resultRender.FetchXml.value);

    ManMis
    Wednesday, February 24, 2010 6:20 AM
  • Hi ,

     

    I am using filtered lookup as suggested above on the onloadform i.e

    crmForm.all.productid("search","searchstring").It works fine .

    The Problem is with the search box which should n't be there .I try to hide it by using crmForm.all.productid.lookupbrowse=1,the filtering doesn't happen.again when i turn it on it does work .

     

    Please help

    Saturday, June 19, 2010 11:22 PM
  • it's useful for me too.
    Monday, June 21, 2010 1:46 AM
  • Helo Adi ,

    I am stuck up with the following problem could you please help.

    The scenario:

    If the customer (account in CRM) is of type "Business",when an order is created for the customer ,and subsequently when you add orderproducts(via salesorder detail entity )The product lookup on the order product screen should fetch only products which are of category Business and not of any other category.

    (Note :I have picklists on both account and products of same kind for classifying customer account and products as Business or Residential)

    At Present as per Jim wang's blog(http://jianwang.blogspot.com/2008/05/mysterious-crm-lookup-ii.html ) I've added the find column and used crmForm.all.Productid.additionalParams=  'search=' + (Value of the searchcolumn);

    After that it is able to filter it.But on the Lookup screen the screen option was visible so i tried to hide by using crmForm.all.productid.lookupbrowse =1 ;after that .I could see that the search field was hidden but the filtering was not happening .

    What ever blogs i saw ,in all the blogs they have hidden the seach and were able to do the filtered look up but i am just wondering why it is not happening in my case ?

     

    Monday, June 21, 2010 5:49 AM
  • Hi Adi,

    We can successfully use the document.FilterLookup() statement on the OnChange on the Quote Product Form as follows:
    document.FilterLookup (crmForm.all.productid, crmForm.all.new_professionalsid);

    But, we are NOT trying to create a fillter based on the "new_professionalsid"of the entiy.
    Rather, we want to lookup the entity in the default manner, but apply a filter to the results that will be returned that will match the "crmForm.all.productid" field with the table entry field '//q1:new_psmjobdescription' 

    The filter would look something like: (crmForm.all.productid == '//q1:new_psmjobdescription') - I know this code is not syntactically correct.

    Have you any suggestions on this:

    We have been following most of the blogs on it and still not found a way to do it. 

    (PS. It is a hosted site, so I cant access Registry entries or get access to the actual server)

    Friday, July 23, 2010 12:39 PM
  • Changed the JS binding code to:

     

    crmForm.new_lookupLeaf.lookupbrowse = 1

    crmForm.new_lookupLeaf.additionalparams = "search=<fetch version="…></fetch>";

     

    In the CRMWeb\_controls\lookup\lookupsingle.aspx wrote this Server Side code at the top of the page.

     

    <script runat="server">

     

    protected

     

    override void OnLoad(EventArgs e)

    {

     

     

         base.OnLoad(e);

         crmGrid.PreRender +=

     

    new EventHandler(crmGrid_PreRender);

    }

     

     

     

    void crmGrid_PreRender(object sender, EventArgs e)

    {

     

     

     

     

         if( Request["search"] + "" != "" && Request["browse"] + "" == "1" )

         {

               crmGrid.AddParameter(

     

    "fetchxml", Request["search"] );

               crmGrid.Parameters.Remove(

     

    "searchvalue");

         }

     

     

     

     

    </script>

     

    That's it

     

     

     

     

    }


    Thanks its working for me in CRM4 after adding the above code in CRMWeb\_controls\lookup\lookupsingle.aspx

    Script to add the fetchXMl on Onload event is

    crmForm.all.new_precautionlevelid.lookupbrowse = 1;
    crmForm.all.new_precautionlevelid.additionalparams = "search=<fetch mapping='logical'><entity name='new_precautionlevels'><all-attributes/><order attribute='new_precautionlevel' descending='false'/><filter type='or'><condition attribute='new_precautionlevel' operator='eq' value='Positive'/><condition attribute='new_precautionlevel' operator='eq' value='Precaution'/></filter></entity></fetch>";

    (Note: new_precautionlevelid is the name of the lookup attribute & new_precautionlevels is the name of the entity)

     

     

     

    Thursday, September 30, 2010 3:20 PM
  • Hi Adi,

    I am using CRM 4.0 and used your apporach (.lookupbrowse=1, .additionalparams = "search=<fetch ....., change _controls\lookup\lookupsingle.aspx etc...)

    This works perfectly, but with side effects. The search textbox in lookup is hidden (.lookupbrowse = 1) and the lookup results span many pages.

    Now the user is forced to browse the result pages maually before picking the wanted subject.

    How can i enable the Search textbox for the user and at the same time hide my custom fetchxml with custom filter conditions.

    Best Regards,

    Nags

    Monday, September 19, 2011 7:43 AM