web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Get Api Version Dynamically For WebApi Requests

Debajit Dutta Profile Picture Debajit Dutta 2,702

Loads of my blog readers wanted to know..here is the perfect link to it.

 Passion Dynamics

In this post I will quickly cover the requirement of dynamically getting API version of dynamics CRM in JavaScript rather then hard coding it , so that in next releases your JavaScript doesn’t breaks. I am referring to this:

1

For Dynamics CRM version 8.2 or below, do this:

var apiVersion = Xrm.Page.context.getVersion();

For Dynamics CRM version 9 or above, do this:

var apiVersion = Xrm.Utility.getGlobalContext().getVersion();

2

It will give you an expended version which includes minor and major versions. Now, all you have to is crop the number to get only initial number such as 9.1 in this case:

var shortVersion= apiVersion.substring(3, myStr.indexOf(“.”) -1);

then finally use it in your request as:

    req.open("GET",Xrm.Utility.getGlobalContext().getClientUrl()+ "/api/data/"+shortVersion+"/systemusers

Hope this helps!

View original post


This was originally posted here.

Comments

*This post is locked for comments