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);
		}
		);
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Get values from a lookup field retrieved from another table in JS

    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 57

#3
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans