locked
Lookup field filter RRS feed

  • Question

  • Hi

    I have the following requirement.

    Created three entites Test, State, City.

    State and City are added in test entity as lookups.

    After selecting state. next when I click on city lookup the system must display only those cities related to state.

    Steps followed:

    On test entity onload event.

    FilterLookup = function(source, target) 

        if (IsNull(source) || IsNull(target)) { return; } 
        var name = IsNull(source.DataValue) ? '' : source.DataValue[0].name; 
        target.additionalparams = 'search=' + name; 
    }

    on test entity State Attribute lookup (On change event )

    var lookupItem = new Array;

    lookupItem = crmForm.all.new_stateid.DataValue;
    var searchVal = lookupItem[0].new_name;
    crmForm.all.new_cityid.additionalparams = ‘search=' + searchVal;

    In Test Entity Test lookup view --> Added Find Colums --> Selected Name and State.

    From long time I am trying this kind of solution but couldnt find right solution.

    Guide me were I am going wrong.

    I followed the below link blog so that if I am successfull in this case I configure according to my requirement.

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

     But no filter is happening. Can any one suggest me were I am going wrong.


    Pavan CRM Consultant
    Wednesday, November 3, 2010 4:38 PM

Answers

  • I tried but no difference. when I click on city lookup no filter had happen.

    I used the following code and steps and is working fine.

    Steps:

    On test entity onload event.

    this.isLoad=true;

    crmForm.new_stateid.OnChange();

    isLoad = false;

    on test entity State Attribute lookup (On change event )

    var field = crmForm.all.new_cityid;

     if(isLoad == false)

    {

     // remove State lookup value on Country change

     field.DataValue=null;

    }

     if(crmForm.all.new_stateid.DataValue == null)

    {

      // Disable state lookup here for new record as there can be no States

      // field.Disabled = true;

    }

    else

    {

      // Ensure that search box is not visible in a lookup dialog

      field.lookupbrowse = 1;

     

      // Pass fetch xml through search value parameter

      field.AddParam("search",

       "<fetch mapping='logical'><entity name='new_city'>"

      + "<filter><condition attribute='new_stateid' operator='eq' value='"

      + crmForm.all.new_stateid.DataValue[0].id

      + "' /></filter></entity></fetch>");

    }

     


    Pavan CRM Consultant
    Monday, November 8, 2010 10:09 AM

All replies

  • Hi, Pavan.

    Line var searchVal = lookupItem[0].new_name; is wrong try to use:

    var searchVal = lookupItem[0].name;

    Also don't forget to check lookupItem for a null.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Proposed as answer by Faisal Fiaz Friday, November 5, 2010 5:21 PM
    • Unproposed as answer by Pavan Kumar Reddy Monday, November 8, 2010 10:09 AM
    Wednesday, November 3, 2010 4:41 PM
    Moderator
  • I tried but no difference. when I click on city lookup no filter had happen.

    I used the following code and steps and is working fine.

    Steps:

    On test entity onload event.

    this.isLoad=true;

    crmForm.new_stateid.OnChange();

    isLoad = false;

    on test entity State Attribute lookup (On change event )

    var field = crmForm.all.new_cityid;

     if(isLoad == false)

    {

     // remove State lookup value on Country change

     field.DataValue=null;

    }

     if(crmForm.all.new_stateid.DataValue == null)

    {

      // Disable state lookup here for new record as there can be no States

      // field.Disabled = true;

    }

    else

    {

      // Ensure that search box is not visible in a lookup dialog

      field.lookupbrowse = 1;

     

      // Pass fetch xml through search value parameter

      field.AddParam("search",

       "<fetch mapping='logical'><entity name='new_city'>"

      + "<filter><condition attribute='new_stateid' operator='eq' value='"

      + crmForm.all.new_stateid.DataValue[0].id

      + "' /></filter></entity></fetch>");

    }

     


    Pavan CRM Consultant
    Monday, November 8, 2010 10:09 AM