Search code examples
javascriptdynamicdynamics-crm-2011dynamics-crm

How to Select values from a lookup


I'm new to to CRM.

I have a look-up. I want to retrieve the column records of the selected lookup.
I tried with this, getting only selected lookup name, id

var lookupObject = Xrm.Page.getAttribute("schemaname");

if (lookupObject != null) 
{

    var lookUpObjectValue = lookupObject.getValue();

    if ((lookUpObjectValue != null))         
    {
     var lookuptextvalue = lookUpObjectValue[0].name;
     var lookupid = lookUpObjectValue[0].id;
     }

  }

How do I get the other column values?


Solution

  • The lookup field contains only the id,name and entityType properties.

    If you want to retrieve other fields of the selected record you need to call the CRM webservices (in this case is enough to use the REST endpoint)

    You can find an example here:

    http://www.crmanswers.net/2013/07/set-accounts-primary-contact-as.html

    and here:

    http://www.crmanswers.net/2013/04/get-current-users-full-name-with.html

    Note that when you use the REST endpoint you need to look for the Schema name. For example the field name is FullName and not fullname