Notifications
Announcements
No record found.
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
You can try
var name = Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].name;
(you can also use "id": Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].id;)
EDIT: Of course I forgot to put getValue there - updated the examples.. Thanks Deepthi Thotakura
Hi ,
If you are using to get lookup details through JavaScript , Here is example :
if (Xrm.Page.data.entity.attributes.get("fieldname").getValue() != null) {
var CustomerId = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].id;
var CustomerName = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].name;
var CustomerType = Xrm.Page.data.entity.attributes.get("feildname ").getValue()[0].entityType;
}
//Display the lookup name
alert(CustomerName);
I hope this helps you replace fieldname with your lookup field name in Form
let me know if you find any errors.
Thanks ,
Deepthi
This is the best answer and actually details all the data that you can get from lookup value.
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.
thank you it works
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?
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
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;
What about other field values of the lookup record ?
Please create a new thread about your queries as this thread got verified already.
Thanks,
Jharana
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2