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

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans