locked
CRM 3.0 Filter Data in a Lookup not working RRS feed

  • Question

  • Hi all,

    I'm trying to create a filtered lookup using the method of Advanced Find for FetchXML. On the form General Profile there are e.g. two lookup fields: General Profile Type and General Profile Type Options. The General Profile Type Options lookup should be filtered according to the selected General Profile Type.

    If have put the following script on the Onload event:

    //conditional lookup for type options
    
    crmForm.all.new_generalprofiletypeoptionsid.lookupbrowse = 1;
    crmForm.all.new_generalprofiletypeoptionsid.additionalparams = "fetchXml=<fetch mapping='logical'><entity name='new_generalprofiletypeoptions'><all-attributes/><filter type='and'><condition attribute='new_generalprofiletypeid' operator='eq' uiname='"+crmForm.all.new_generalprofiletypeid.DataValue[0].name+"' value="'+crmForm.all.new_generalprofiletypeid.DataValue[0].id+'"/></filter></entity></fetch>";
    crmForm.all.new_generalprofiletypeoptionsid.additionalparams += "&selObjects=2&findValue=0";
    

    Unfortunately this is not working. It keeps showing the "normal" lookup window... and no filtering. There is a similar script on account for the lookup of primary contact. That is working fine. I also used another, but similar script, but that gave the error "Query Builder Error. No Attribute".

    Is there someone who can help me out? Thanks!

    Friday, June 18, 2010 12:59 PM

Answers

  • Did you tried like this only on formload event

    function FilterlookupsFx()
    {//Please check for updated script

    crmForm.all.new_generalprofiletypeoptionsid.lookupbrowse = 1;
    crmForm.all.new_generalprofiletypeoptionsid.additionalparams = "fetchXml=<fetch mapping='logical'><entity name='new_generalprofiletypeoptions'><all-attributes/><filter type='and'><condition attribute='new_generalprofiletypeid' operator='eq' uiname='"+crmForm.all.new_generalprofiletypeid.DataValue[0].name+"' value="'+crmForm.all.new_generalprofiletypeid.DataValue[0].id+'"/></filter></entity></fetch>";
    crmForm.all.new_generalprofiletypeoptionsid.additionalparams += "&selObjects=2&findValue=0";
    }

    crmForm.all.item("new_generalprofiletypeoptions").attachEvent("onchange",FilterlookupsFx);   

     

     


    Mahain
    Friday, June 18, 2010 1:43 PM
    Moderator

All replies

  • Hi,

    you can also use script mentioned in below post

    http://advantageworks.blogspot.com/2008/02/pseudo-filtered-lookup-dialog-in.html

    Hope it will help you !!


    Mahain
    Friday, June 18, 2010 1:05 PM
    Moderator
  • Hi,

    I tried that method as well, but I did not get it working in 3.0 (I did though in 4.0).

    I just discovered that I switched a comma. It works on the onload now :D.
    However it should work on change of the Type Options field. But when I open a new record and select everything from blank nothing happens. Can this be solved with a FireOnChange statement on the Onload?

    Thanks!

    Friday, June 18, 2010 1:15 PM
  • Hi,

    you can try this script on formload

    function FilterlookupsFx()
    {
    //code to filter lookup
    }
    crmForm.all.item("new_generalprofiletypeoptions").attachEvent("onchange",FilterlookupsFx);


    Mahain
    Friday, June 18, 2010 1:26 PM
    Moderator
  • Hi,

    I took the script Mahender suggests and put it on the onload.

    The other script is on the onchange of the type options. Is this correct?

    Unfortunately it does not work...

    Friday, June 18, 2010 1:38 PM
  • Did you tried like this only on formload event

    function FilterlookupsFx()
    {//Please check for updated script

    crmForm.all.new_generalprofiletypeoptionsid.lookupbrowse = 1;
    crmForm.all.new_generalprofiletypeoptionsid.additionalparams = "fetchXml=<fetch mapping='logical'><entity name='new_generalprofiletypeoptions'><all-attributes/><filter type='and'><condition attribute='new_generalprofiletypeid' operator='eq' uiname='"+crmForm.all.new_generalprofiletypeid.DataValue[0].name+"' value="'+crmForm.all.new_generalprofiletypeid.DataValue[0].id+'"/></filter></entity></fetch>";
    crmForm.all.new_generalprofiletypeoptionsid.additionalparams += "&selObjects=2&findValue=0";
    }

    crmForm.all.item("new_generalprofiletypeoptions").attachEvent("onchange",FilterlookupsFx);   

     

     


    Mahain
    Friday, June 18, 2010 1:43 PM
    Moderator
  • Getting closer... I used the script on the onload event only. The onchange is empty.

    However I now get the following error:

    There was an error with this field's customized event.
    Field: crmForm
    Event: onload
    Error: 'crmForm.all.item(...)' is null or not an object

    Any ideas?

    Thanks for the help so far.

    Friday, June 18, 2010 2:17 PM
  • Hi,

    Can you please make sure the field schema name and function name are correct all over ??

     


    Mahain
    Friday, June 18, 2010 2:23 PM
    Moderator
  • Hi,

    Check, the error is gone when creating a new record.

    However when selecting a Type, there is no filtering when trying to select the Type Options. It now shows the "standard" lookup showing all the Type Options...

    Strange...

    Friday, June 18, 2010 2:30 PM
  • It is working now, I think...

    I have put the FetchXML script in a function. I now call this function from the on change of the Profile Type. I now have a filtered view of the Profile Type Options.

    Thanks Mahain for helping me on my way!

    Friday, June 18, 2010 3:05 PM