Using Web API Function in CRM 2016 - Part Two

In our last article we discussed standard functions, today we are going to discuss Query Function. These functions are basically conditional operators, so there is conditional operator corresponding to every query function. We can get a complete list of query function references from here. We can use these functions similar to standard function, but we just need to make sure to include full name of the function while using it.
The following is the sample code for using query function: 
  1. function GetNextMonthEvents() {  
  2.     var serverURL = Xrm.Page.context.getClientUrl();  
  3.     var req = new XMLHttpRequest();  
  4.     req.open("GET", serverURL + "/api/data/v8.0/him_events?$select=him_eventname&$filter=Microsoft.Dynamics.CRM.NextMonth(PropertyName='him_eventstartdate')"true);  
  5.     req.setRequestHeader("Accept""application/json");  
  6.     req.setRequestHeader("Content-Type""application/json; charset=utf-8");  
  7.     req.setRequestHeader("OData-MaxVersion""4.0");  
  8.     req.setRequestHeader("OData-Version""4.0");  
  9.     req.onreadystatechange = function() {  
  10.         if (this.readyState == 4 /* complete */ ) {  
  11.             req.onreadystatechange = null;  
  12.             if (this.status == 200) {  
  13.                 var data = JSON.parse(this.response);  
  14.                 alert(data.value.length);  
  15.             } else {  
  16.                 var error = JSON.parse(this.response).error;  
  17.                 alert(error.message);  
  18.             }  
  19.         }  
  20.     };  
  21.     req.send();  
  22. }   
In above sample code we are using NextMonth query function. This query function takes one parameter, which is the name of the attribute that we want to validate. We are using this function to get a list of event sthat are happening next month. So it will query our custom event entity and will display the number of events which are scheduled next month. We can create script web resources and use above code there. If you are new to web resources refer to my earlier posts for how to create web resources and use them.

Stay tuned for more Dynamics CRM updates!!
Read more articles on Dynamics CRM:
 


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.