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 :
Customer experience | Sales, Customer Insights,...
Answered

Question about retrieveRecord (Client API reference)

(0) ShareShare
ReportReport
Posted on by 821

While updating  our D365 instance to use the unified interface we have also started  replacing the older (javaScript)  odata requests with the Xrm.WebApi. Just today i stumbled across the fact that for example the Xrm.WebApi.retrieveRecord does not appear to bring back the GUIDs of lookup fields on the entity eg primary contact on Account., this was not the case for the older odata call which i was trying to  mimic to save time refracting my code. Can anyone recommend the beast approach.

Thank G

function oDataRetrieve(entityName, guid, columnSet, callbackHandler) {

var orgPath = Xrm.Page.context.getClientUrl();
var restEndPoint = orgPath + "/XRMServices/2011/OrganizationData.svc";

var retrieveRequest = new XMLHttpRequest();
retrieveRequest.open("GET", restEndPoint + "/" + entityName + "Set(guid'" + guid + "')?$select=" + columnSet, isAsync);
retrieveRequest.setRequestHeader("Accept", "application/json");
retrieveRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRequest.send();

......

** Replaced with ***

RetrieveRecord: function (entityName, guid, columnSet, callbackHandler) {

var apiParms = "?$select=" + columnSet;

Xrm.WebApi.retrieveRecord(entityName, guid, apiParms).then(
function success(result) {
// console.log("Retrieved values: Name: " + result.name);
// perform operations on record retrieval
callbackHandler(result);
},
function (error) {
// Something went wrong during the data retrieval
Xrm.Navigation.openErrorDialog({ message: error.message });
}
);
},

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    In newer version of API lookups behave differently. If your lookup field is "new_lookupid" webapi field for it will be "_new_lookupid_value".

    You can check this post as a reference - carldesouza.com/.../

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    I would recommend you to install Rest builder on your crm instance and generate API code from this tool.

    Download link - github.com/.../releases

    Request

    Xrm.WebApi.online.retrieveMultipleRecords("account", "?$select=_primarycontactid_value&$filter=_primarycontactid_value ne null&$top=1").then(

       function success(results) {

           for (var i = 0; i < results.entities.length; i++) {

               var _primarycontactid_value = results.entities[i]["_primarycontactid_value"];

               var _primarycontactid_value_formatted = results.entities[i]["_primarycontactid_value@OData.Community.Display.V1.FormattedValue"];

               var _primarycontactid_value_lookuplogicalname = results.entities[i]["_primarycontactid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

           }

       },

       function(error) {

           Xrm.Utility.alertDialog(error.message);

       }

    );

    Response

    entities:[

    {

    @odata.etag:"W/"2566732"",

    _primarycontactid_value@OData.Community.Display.V1.FormattedValue:"Vincent Lauriant",

    _primarycontactid_value@Microsoft.Dynamics.CRM.associatednavigationproperty:"primarycontactid",

    _primarycontactid_value@Microsoft.Dynamics.CRM.lookuplogicalname:"contact",

    _primarycontactid_value:"465b158c-541c-e511-80d3-3863bb347ba8",

    accountid:"475b158c-541c-e511-80d3-3863bb347ba8"

    }

    ]

    As andrew suggested use _primarycontactid_value to get GUID of lookup field.

    If found helpful, Please mark my answer verified.

  • Suggested answer
    gman0104 Profile Picture
    821 on at

    Thanks Andrew this has answered my question :)

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans