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...
Suggested Answer

Get values from a lookup field retrieved from another table in JS

(0) ShareShare
ReportReport
Posted on by 20

HI Guys,

Fairly new to this so I am having some issues with getting the actual value of a lookup field in js script.

I am trying to reference a custom value in the accounts table all works fine but i can't get the actual value.

Here is the code.

        var accountId = Xrm.Page.getAttribute("cr787_account").getValue()[0].id;

      	Xrm.WebApi.online.retrieveRecord("account", accountId, "?$select=_cr787_gstperiod_value,chpms_gst_period,cr787_preparegst").then(
		function success(result) {
			//console.log(result);
			// Columns
			var accountid = result["accountid"]; // Guid
			var cr787_gstperiod = result["_cr787_gstperiod_value"]; // Lookup
			var cr787_gstperiod_formatted = result["_cr787_gstperiod_value@OData.Community.Display.V1.FormattedValue"];
			var cr787_gstperiod_lookuplogicalname = result["_cr787_gstperiod_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
			var lookupValP = new Array();
   			lookupValP[0] = new Object();
   			lookupValP[0].id = cr787_gstperiod;
   			lookupValP[0].name = cr787_gstperiod_formatted;
   			lookupValP[0].entityType = cr787_gstperiod_lookuplogicalname;
			alert(cr787_gstperiod[0].name);			

			var chpms_gst_period = result["chpms_gst_period"]; // Choice
			var chpms_gst_period_formatted = result["chpms_gst_period@OData.Community.Display.V1.FormattedValue"];
			alert(chpms_gst_period[0].name);

			var cr787_preparegst = result["cr787_preparegst"]; // Boolean
			var cr787_preparegst_formatted = result["cr787_preparegst@OData.Community.Display.V1.FormattedValue"];
			alert(cr787_preparegst);
			alert(cr787_preparegst_formatted);
			
		},
		function(error) {
			console.log(error.message);
		}
		);
I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please explain what exactly you mean by "i can't get the actual value". The description itself is a bit vague.

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