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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Get lookup value from XMLHTTPRequest

(0) ShareShare
ReportReport
Posted on by 121

I created js function to get record from different entity in my organization. 

function retrieveRecord() {
	var recordId = "62066436-52de-eb11-b802-00155d6e5e00";
    //var clientURL = Xrm.Page.context.getClientUrl();
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl()   "/api/data/v8.2/lnkt_actiontakens(" recordId  ")?$select=lnkt_name,lnkt_Device,lnkt_SubDevice,lnkt_Damage,lnkt_RootCause", true);

    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4) {
            req.onreadystatechange = null;
            if (this.status == 200) {
                var data = JSON.parse(this.response);     
				var action_name = data.lnkt_name;
				var device = data.lnkt_device;
				if(device != null)
				{
					var deviceId = device[0].id;
				}
				alert("Action name: "   action_name   " ,Device ID: "   deviceId);
            }
            else {
                var error = JSON.parse(this.response).error;
                alert("Error retrieving Record – "   error.message);
            }
        }
    };
    req.send();
}

I can get primary field which is "lnkt_name" (Single Line of Text). However i can't get the value of look up (lnkt_device). In the alert its return undefinied. How to get the  lookup id, lookup entityname, and lookup label. Thanks

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi FikriHailal,

    You can build request easily with the tool—CRM REST Builder:

    Download page: https://github.com/jlattimer/CRMRESTBuilder

    Download it and import it to solution, then one icon will appear like following screenshot:

    3833.pastedimage1625641107271v6.png

    For example, Contact has one lookup field(Account name):

    5280.pastedimage1625640694978v1.png

    Settings in CRM REST Builder:

    2728.pastedimage1625640772786v3.png

    Clicking Create request:

    0458.pastedimage1625640906416v4.png

    Execute code:

    2450.pastedimage1625640958891v5.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at
  • Community Member Profile Picture
    on at

    Hi Partner,

    Has the problem been solved? Any updates?

    Please click Yes under "Did this answer your question?" to close this thread.

     3757.pastedimage1625825335014v1.png

    Thanks. 

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • FikriHailal Profile Picture
    121 on at

    Thanks. I used crm rest builder and its work

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 55

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans