
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);
}
); Hello,
Can you please explain what exactly you mean by "i can't get the actual value". The description itself is a bit vague.