Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

get lookup field value through javascript

(0) ShareShare
ReportReport
Posted on by 2,510

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

  • Community Member Profile Picture
    on at
    RE: get lookup field value through javascript

    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!)

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at
  • Invictus Technology Solutions Profile Picture
    5 on at
    RE: get lookup field value through javascript

    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.

  • Jharana Baliyar Singh Profile Picture
    2,667 on at
    RE: get lookup field value through javascript

    Please create a new thread about your queries as this thread got verified already.

    Thanks,

    Jharana

  • KashyapT Profile Picture
    106 on at
    RE: get lookup field value through javascript

    What about other field values of the lookup record ?

  • Saddamk206 Profile Picture
    777 on at
    RE: get lookup field value through javascript

    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;

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: get lookup field value through javascript

    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

  • Community Member Profile Picture
    on at
    RE: get lookup field value through javascript

    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?

  • Community Member Profile Picture
    on at
    RE: get lookup field value through javascript

    thank you it works

  • Suggested answer
    LMP Profile Picture
    680 on at
    RE: get lookup field value through javascript

    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.

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.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans