Hi, I have requirement to get a customer name from lookup field, it looks like " xrm.page.getattributes" doesn't in this way. please help
*This post is locked for comments
Hi, I have requirement to get a customer name from lookup field, it looks like " xrm.page.getattributes" doesn't in this way. please help
*This post is locked for comments
What is the [0] for?
The lookups are implemented as arrays. So to read them you have to access the first member -- [0]. The only time you might find [1]...[n] is with ActivityParties -- To, From, CC, BCC fields on activities -- which may actually hold more than one.
And, no. The structures on the array are always id/name/entityType. (Exactly enough to form a hyperlink to the record!)
Here is a article to Get and Set Value for all data Types in Dynamic CRM.
https://vjcity.blogspot.com/2019/07/how-to-get-and-set-value-for-different.html
Hi Deepti,
Thanks for the Valuable Information and please provide the information about how to get the look up Id using plug-in's as well If you are able to do it.
Thanks,
Harsha.
Please create a new thread about your queries as this thread got verified already.
Thanks,
Jharana
What about other field values of the lookup record ?
Hi,
try these:-
var Id = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].id;
var Name = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].name;
or Can Use if not work(Use window.parent. before Xrm)
var Id = window.parent.Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].id;
var rName = window.parent.Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].name;
Hello,
This is you need when you are getting value frof lookup field which contains I'd and name .for that you need to write like below
getValue()[0].id
getValue()[0].name
Hope this helps
Hello , I currently need help and have multiple questions about this.
What is the [0] for?
Let's say I want to get something else than the name, can i use "getValue()[0].customfield" to get the custom field in question?
thank you it works
Additional info.
You have to check first if the field is not null before getting its value otherwise you will get a JavaScript error.
if (Xrm.Page.getAttribute(fieldName) != null)
var id = Xrm.Page.getAttribute(fieldName).getValue()[0].id; // If you would like to get the id of the record on the lookup field.