Reputation: 13
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?
Upvotes: 0
Views: 6903
Reputation: 1
I use Json.parse()
from my object lookup and store the value in a variable. example:
accountJson = JSON.parse(accountid[0].keyValues);
accountid.name.value;
Upvotes: 0
Reputation: 15128
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
Upvotes: 2
Reputation: 19
You can do something like this,
var lookupObject = Xrm.Page.getAttribute("schemaname");
if (lookupObject != null)
{
var selectedrecordvalues = lookupObject.getValue()[0].keyValues;
//key values will come as array.
}
Upvotes: 1