Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to get field values from a lookup field entity

Posted on by 390

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

  • Victor Onyebuchi Profile Picture
    Victor Onyebuchi 390 on at
    RE: How to get field values from a lookup field entity

    Thanks Andrew once again.

  • Victor Onyebuchi Profile Picture
    Victor Onyebuchi 390 on at
    RE: How to get field values from a lookup field entity

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get field values from a lookup field entity

    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.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to get field values from a lookup field entity

    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.

  • Rajesh Chungath Profile Picture
    Rajesh Chungath 465 on at
    RE: How to get field values from a lookup field entity

    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

  • LMP Profile Picture
    LMP 676 on at
    RE: How to get field values from a lookup field entity

    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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to get field values from a lookup field entity

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans