Making Xrm.WebApi.retrieveRecord Synchronous calls in Common Data Service (D365 fo CE)

With v9 a lot of changed. One of the major changes is client web API, some of calls were made deprecated and some were added. For example, Xrm.WebApi.

The new ‘Xrm.WebApi.retrieveRecord(entityLogicalName, id, options).then(successCallback, errorCallback)’ can’t be made synchronous. But imagine situation, in which you need to go through multiple entities (lookups). In this scenario, you need the result of retrieved record to access the next record. So how can this be done?

In this case, you need to use successCallback, which can be nested – so you can go through multiple entities:

But if you are like me, you probably already found this out on your own. What’s the issue with this solution? You don’t want to nest calls to targeted record in advance, you want to specify path to this record and what should be done with the result. So, you can use the same code snippet.

I wrote simple recursion function that does exactly what’s described above. This may be exactly what you were looking for:

I will write something more advanced next time, no worries.

2 thoughts on “Making Xrm.WebApi.retrieveRecord Synchronous calls in Common Data Service (D365 fo CE)”

    1. Hello Andrew,
      you are absolutely right. We were discussing this with my colleagues and choose this option because of the limitation to one expand on retrieveMultipleRecords call. But what I didn’t considered is FetchXML query instead of OData query. I haven’t tested it, but it should work.

      So thanks for the comment.

      We use this method, because I think it’s more pleasant for the customizers of Dynamics Solutions.

      When I get a little more time, I’ll try to edit the post with your input.

      Thanks again.

Leave a Reply