locked
How to populate the lookup field value in to text field, OnChange event of lookup field ? RRS feed

  • Question

  • Hi,

    I need to  Build a java script on change of “Patient Case ID “ look up. have to populate Patient case id on Text field.

     Thanks

    Srikanth Reddy

     

     

    Saturday, September 11, 2010 10:02 AM

Answers

  • Hi Srikanth,

    If you simply want to populate the text field with whatever the value of your lookup is, then something like this in the onChange event of your lookup field should do the trick:

    crmForm.all.[Text Field Schema].DataValue = crmForm.all.[Lookup Field Schema].DataValue[0].name;

    Thanks,
    Maryse

     


    The xRM Architect:
    • Proposed as answer by Amarsen Vangoor Saturday, September 11, 2010 1:38 PM
    • Marked as answer by Jim Glass Jr Monday, September 13, 2010 3:23 PM
    Saturday, September 11, 2010 12:27 PM

All replies

  • Hi Srikanth,

    If you simply want to populate the text field with whatever the value of your lookup is, then something like this in the onChange event of your lookup field should do the trick:

    crmForm.all.[Text Field Schema].DataValue = crmForm.all.[Lookup Field Schema].DataValue[0].name;

    Thanks,
    Maryse

     


    The xRM Architect:
    • Proposed as answer by Amarsen Vangoor Saturday, September 11, 2010 1:38 PM
    • Marked as answer by Jim Glass Jr Monday, September 13, 2010 3:23 PM
    Saturday, September 11, 2010 12:27 PM
  • Hi

    CRM Lookup support an array that has the following predefined properties i.e. id, name, type and typename. Here is an example on how it works [OnChange of your lookup attribute]

     

    var lookupItem = new Array;
    
    // This will get the lookup for the attribute primarycontactid on the Account form.
    lookupItem = crmForm.all.primarycontactid.DataValue;
    
    // If there is data in the field, show it in a series of alerts.
    if (lookupItem[0] != null)
    {
     // The text value of the lookup.
     alert(lookupItem[0].name);
    
     // The GUID of the lookup.
     alert(lookupItem[0].id);
    
     // The entity type name.
     alert(lookupItem[0].typename);
    
     // The entity type code of the lookup: 1=account, 2= contact.
     // This attribute is deprecated. Use typename instead.
     alert(lookupItem[0].type);
    }

     

    More on how to use lookup here

    http://technet.microsoft.com/en-us/library/aa681853.aspx



    Hope this helps. Amar
    • Proposed as answer by Amarsen Vangoor Saturday, September 11, 2010 8:23 PM
    Saturday, September 11, 2010 1:49 PM