locked
How to bring a Lookup's value to next lookup Search box of another Lookup?????????????????? RRS feed

  • Question

  • Hi all,

          Hi all i need a help when a Field's Lookup value is Selected lets say (FINID) as 00004.. then the Next Field (PRJID) value's Search box Look Up value be 00004..

         Please share your Java Script code to Procced. I request you to give only the Javascript Code....

    Note: We should not user CRMform.all.finid.value.


    • Edited by JERRY_TP Friday, April 5, 2013 3:03 PM
    Friday, April 5, 2013 3:02 PM

Answers

  • If I understand your question right - when you select a value for one look up, you also want to automatically populate a look up of the same type?

    function Field1_OnChange() {
        Xrm.Page.getAttribute("new_field2").setValue(Xrm.Page.getAttribute("new_field1").getValue());
    }



    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, April 5, 2013 4:01 PM
    Moderator
  • Hi, 

    if you want to search Project Finance Id in PlanArena Project Code field you must use a filtered lookup. For example: 

    Youi want to search all PlanArena Project Code that the primary fild name begin with  primary fild name of Project Finance Id.

    Project Finance Id=00001
    PlanArena Project Code =00001 - "Other words"

    Example in Java Script Code

    var defaultViewId;
     
    // FUNCTION: formOnLoad
    function formOnLoad(entitysourceFieldName, lookupFieldName) {
     
      defaultViewId = Xrm.Page.getControl(lookupFieldName).getDefaultView();
      setLookup(entityFieldName, lookupFieldName, false);
     
    }
     
    // FUNCTION: setLookup
    function setLookup(entityFieldName, lookupFieldName, resetSelection) {
     
        // Get the selected Id Entity Source in the [entityFieldName] indicated control
        var account = Xrm.Page.getAttribute(entityFieldName).getValue();
     
        if ( entitysource!= null )
        {
          var entitysourceid = entitysource[0].id;
          var entitysourcename = entitysource[0].name;
     
          if ( resetSelection == true )
          {
            // reset old selection for Entity Target
            Xrm.Page.getAttribute(lookupFieldName).setValue(null);
          }
     
          // use randomly generated GUID Id for our new view
          var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}";
          var entityName = "name of entity";
     
          // give the custom view a name
          var viewDisplayName = "Project Finace Id Begin with " + fieldname+ "";
     
          var fetchXml = "this is the fetch retrived by Advanced Search"
     
          // build Grid Layout
          var layoutXml = "<grid name='resultset' " +
                                   "object='1' " +
                                   "jump='contactid' " +
                                   "select='1' " +
                                   "icon='1' " +
                                   "preview='1'>" +
                               "<row name='result' " +
                                    "id='contactid'>" +
                                 "<cell name='field to dislay' " +
                                       "width='200' />" +
                                 "<cell name='field to dislay' " +
                                       "width='250' />" +
                                 "<cell name='field to dislay' " +
                                       "width='250' />" +
                               "</row>" +
                             "</grid>";
     
          // add the Custom View to the indicated [lookupFieldName] Control
          Xrm.Page.getControl(lookupFieldName).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
        }
        else
        {
          // no Entity Target selected, reset Contact Lookup View to the default view such that all Entity Target are displayed for selection
          Xrm.Page.getControl(lookupFieldName).setDefaultView(defaultViewId);
        }
    }

    Also Check this.

    This might be helpful, if so mark this as "Answer" or "Vote as helpful"

    ________________________________________________________________

    NG


    My Blog: http://nicolagrillo.blogspot.it/


    Saturday, April 6, 2013 7:12 AM

All replies

  • If I understand your question right - when you select a value for one look up, you also want to automatically populate a look up of the same type?

    function Field1_OnChange() {
        Xrm.Page.getAttribute("new_field2").setValue(Xrm.Page.getAttribute("new_field1").getValue());
    }



    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, April 5, 2013 4:01 PM
    Moderator
  • Hi, 

    if you want to search Project Finance Id in PlanArena Project Code field you must use a filtered lookup. For example: 

    Youi want to search all PlanArena Project Code that the primary fild name begin with  primary fild name of Project Finance Id.

    Project Finance Id=00001
    PlanArena Project Code =00001 - "Other words"

    Example in Java Script Code

    var defaultViewId;
     
    // FUNCTION: formOnLoad
    function formOnLoad(entitysourceFieldName, lookupFieldName) {
     
      defaultViewId = Xrm.Page.getControl(lookupFieldName).getDefaultView();
      setLookup(entityFieldName, lookupFieldName, false);
     
    }
     
    // FUNCTION: setLookup
    function setLookup(entityFieldName, lookupFieldName, resetSelection) {
     
        // Get the selected Id Entity Source in the [entityFieldName] indicated control
        var account = Xrm.Page.getAttribute(entityFieldName).getValue();
     
        if ( entitysource!= null )
        {
          var entitysourceid = entitysource[0].id;
          var entitysourcename = entitysource[0].name;
     
          if ( resetSelection == true )
          {
            // reset old selection for Entity Target
            Xrm.Page.getAttribute(lookupFieldName).setValue(null);
          }
     
          // use randomly generated GUID Id for our new view
          var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}";
          var entityName = "name of entity";
     
          // give the custom view a name
          var viewDisplayName = "Project Finace Id Begin with " + fieldname+ "";
     
          var fetchXml = "this is the fetch retrived by Advanced Search"
     
          // build Grid Layout
          var layoutXml = "<grid name='resultset' " +
                                   "object='1' " +
                                   "jump='contactid' " +
                                   "select='1' " +
                                   "icon='1' " +
                                   "preview='1'>" +
                               "<row name='result' " +
                                    "id='contactid'>" +
                                 "<cell name='field to dislay' " +
                                       "width='200' />" +
                                 "<cell name='field to dislay' " +
                                       "width='250' />" +
                                 "<cell name='field to dislay' " +
                                       "width='250' />" +
                               "</row>" +
                             "</grid>";
     
          // add the Custom View to the indicated [lookupFieldName] Control
          Xrm.Page.getControl(lookupFieldName).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
        }
        else
        {
          // no Entity Target selected, reset Contact Lookup View to the default view such that all Entity Target are displayed for selection
          Xrm.Page.getControl(lookupFieldName).setDefaultView(defaultViewId);
        }
    }

    Also Check this.

    This might be helpful, if so mark this as "Answer" or "Vote as helpful"

    ________________________________________________________________

    NG


    My Blog: http://nicolagrillo.blogspot.it/


    Saturday, April 6, 2013 7:12 AM
  • Hi Lattimer,

         Thanks for our reply,

         Your understanding is slight Correct.

         will Explain you Very Clear....... We are having Two look up Fields one is FINID and another one is PRJID..

    Step 1:  Selecting a Value in Finid --> Click Look Up --> Lot of Values will display in a box so we are Picking from there as 00004.

    Step 2 : Now selecting a Second Field PRJID --> Click Lookk up --> at that time in Search box this 00004 only wanna to be there.

    For that we are using below code, its working fine, but we need this new altered code..

    function new_financeidid_onchange()

    {

     

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

    {

    var new_financeidid = document.getElementById( "new_financeidid" );

    var lookupItems = new_financeidid.items[0].values;

    //alert(lookupItems[2].value+lookupItems[1].value+lookupItems[0].value);

    crmForm.all.new_grossmargin.DataValue=lookupItems[2].value;

     

    }

    crmForm.all.new_projectid.DataValue=null;

    crmForm.all.new_project_test.DataValue=null;

    document.FilterLookup(crmForm.all.new_financeidid, crmForm.all.new_projectid);

     

    }

     

    Onload:

    crmForm.all.new_financeidid.additionalparams = 'search=' + crmForm.all.customerid.DataValue[0].name;

    Saturday, April 6, 2013 9:23 AM