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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Getting Lookup field Value

(0) ShareShare
ReportReport
Posted on by

How to get different field values in a lookup field other than primary field value form another entity.

I have the same question (0)
  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Partner,

    Lookup field only save three properties: record id, record name and record entity name, it is by design.

    You could create an extra query request to get more fields of the selected record.

    The code below is JavaScript version.

    var entityId = Xrm.Page.getAttribute("lookup_field_name").getValue()[0].id.replace('{', '').replace('}', '').toLowerCase();
    
    var entityName = Xrm.Page.getAttribute("lookup_field_name").getValue()[0].entityType;
    
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl()   "/api/data/v8.2/"   entityName   "s"   "("   entityId   ")", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var result = JSON.parse(this.response);
                console.log(result);
            } else {
                alert(this.response);
            }
        }
    };
    req.send();

    Please take articles below as reference for lookup field description:

    https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg334767(v=crm.8)#retrieve-data-about-lookup-properties

    https://docs.microsoft.com/en-us/previous-versions/dynamics-crm4/developers-guide/cc189833(v=msdn.10)

    Regards,

    Clofly

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Use expand properties in web api to get other field from lookup entity record.

    GET [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001)?$select=name&$expand=primarycontactid($select=contactid,fullname) HTTP/1.1  

    As you can see in above api call, We are getting contact full name from primary contact lookup on Account.

    If found helpful, Please mark my answer verified.

  • Suggested answer
    Aditya Profile Picture
    260 on at

    Hi,

    You can use the expand in your query to retrieve the lookup field value from another entity using Xrm.Webapi. An example is shown below :-

    //getting of userid from the context
    var userId = Xrm.Utility.getGlobalContext().userSettings.userId.replace("{", "").replace("}", "");

    //fetching user by id and expanding roles to get role names
    Xrm.WebApi.retrieveRecord("systemuser", userId, "?$expand=systemuserroles_association($select=name)").then(
    function success(result) {

    //looping through all the roles available for user
    for (var i = 0; i < result.systemuserroles_association.length; i++) {
    //getting current role name
    var roleName = result.systemuserroles_association[i]["name"];
    }


    },
    function (error) {
    Xrm.Navigation.openAlertDialog({ text: error.message });
    }

    Please mark the answer as verified if it is useful to you !!

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans