web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get field values from a lookup field entity

(0) ShareShare
ReportReport
Posted on by 410

Hi All,

My javascript skills is still shaky,I want to know how to get values from a lookup field entity using javascript. After retrieving the lookup field on the form, like the below; 

var name = Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].name;

How do i go one step deeper to retrieve values of fields from the retrieved lookup field?

Thank for the help in advance.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    To get values you will have to use Crm Endpoints. Here are examples:

    docs.microsoft.com/.../mt770365(v%3dcrm.8)

    If you're 9.xthen you can use Xrm.WebApi - butenko.pro/.../microsoft-dynamics-365-v9-0-usage-of-new-oob-webapi-functions-part-1

  • LMP Profile Picture
    680 on at

    Hi Victor,

    From a lookup field, you can get the Name, Id and EntityType of the record. Below screenshot shows how to get them.

    2018_2D00_12_2D00_04_5F00_09h40_5F00_26.png

    If you are using Dynamics 365 version 9.0+, you should start using formContext and globalContext instead of Xrm.Page since Xrm.Page will be deprecated soon. Check the below link for more information regarding this.

    https://community.dynamics.com/crm/b/briteglobalsolutions/archive/2018/01/01/migrating-your-client-api-to-dynamics-365-ce-v9-part-i

  • Rajesh Chungath Profile Picture
    467 on at

    If you want to retrieve data from lookup entity

     Get record id and entity type from lookup then perform a web API call to retrieve required fields.

      Please follow the links

       docs.microsoft.com/.../query-data-web-api

       docs.microsoft.com/.../mt770365(v%3dcrm.8)

       github.com/.../CRMRESTBuilder

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Victor,

    You can refer the below link on retrieving the lookup values.

    community.dynamics.com/.../get-lookup-value-from-other-entity-and-set-it-on-the-form-using-web-api-in-microsoft-dynamics-crm

    As you have started with JavaScript, I would also like to introduce you to the Rest Builder tool (if you are not already aware). This is the easiest way to build web api query as well as execute it and see the results.

    Refer this blog for details: carldesouza.com/dynamics-crm-rest-builder

    You can download the tool here- github.com/.../releases

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Victor, You can get your solution by using below code

    if (Xrm.Page.getAttribute("<FIELD_NAME>).getValue() != null) {
            var LookupArray = new Array();
            LookupArray = Xrm.Page.getAttribute("<FIELD_NAME>").getValue();
           if (LookupArray != null) {
                 var LookUpName = LookupArray [0].name;
                var LookUpId = LookupArray [0].id;
                var LookUpentityType = LookupArray [0].entityType;
           }
    }

    Hope this will help.

  • Victor Onyebuchi Profile Picture
    410 on at

    Thanks Ravi. I will look into the tool, as i have been having problems even debugging javascript.

  • Victor Onyebuchi Profile Picture
    410 on at

    Thanks Andrew once again.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans