If you are developer, you should be familiar with functions. It is a reusable piece of code which can be used to perform different operations based on their definition.
CRM 2016 introduced Web API function which can be used to perform different CRM operations. The following are the two functions available in Web API:
In this article we will be discussing standard function. Web API function is used to retrieve information from CRM, every function basically represents one request in
IOrganization service which can return entity collection or complex type. These functions can be generic or can be associated with specific entity, if function is related to specific entity it is known as bound function and if they are generic, not associated with any entity they are known as unbound function. We can get complete list of function reference from
here.
We can call function by appending function name with parameters like below:
serverURL + “/api/data/v8.0/”+Functionname(parameter1,parameter2,..n)
The following is the complete code for using RetrieveVersion function, which can be used to get current CRM version:
- function GetCRMVersion() {
-
- var serverURL = Xrm.Page.context.getClientUrl();
-
- var req = new XMLHttpRequest();
- req.open("GET", serverURL + "/api/data/v8.0/RetrieveVersion()", true);
- req.setRequestHeader("Accept", "application/json");
- req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
- req.setRequestHeader("OData-MaxVersion", "4.0");
- req.setRequestHeader("OData-Version", "4.0");
- req.onreadystatechange = function() {
- if (this.readyState == 4 ) {
- req.onreadystatechange = null;
- if (this.status == 200)
- var data = JSON.parse(this.response);
- alert("You are using Microsoft Dynamics CRM "+data.Version);
- } else {
- var error = JSON.parse(this.response).error;
- alert(error.message);
- }
- }
- };
- req.send();
- }
Once we will execute this code we will get current CRM version alert like below:
Stay tuned for more Dynamics CRM updates!
Read more articles on CRM: