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 :

XMLHttpRequest vs Xrm.WebApi

Michael Ghebremedin Profile Picture Michael Ghebremedin 107

 

XMLHttpRequest vs Xrm.WebApi

If you have written JavaScript code for Dynamics 365 you have seen the use of XMLHttpRequest or Xrm.WebApi to make server-side calls. The question is which one is the right one to use?
So, let’s analyze the two types of calls.

XMLHtttpRequest

1.       Synchronous

a.       Sample Code

var req = new XMLHttpRequest();

req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts", false);

2.       Asynchronous

a.       Sample Code

var req = new XMLHttpRequest();

req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts", true);

So, passing true parameter is going to make asynchronous call while passing it false is going to make a Synchronous call.

Xrm.WebApi

1.       Asynchronous

a.       There is no way to make a synchronous call, even if you are going to use chaining or await keyword it still going to be an asynchronous call.

 
In conclusion if you are looking for an asynchronous call you can use

1.       Xrm.WebApi

2.       XMLHttpRequest with true parameter

If you want to make Synchronous call, then your choice is quite simple use XRMHttpRequest.
 

This was originally posted here.

Comments

*This post is locked for comments

Liquid error: parsing "/blogs/post/?postid=%27nvOpzp;%20AND%201=1%20OR%20(%3C%27%22%3EiKO))," - Too many )'s.