Odata is now in a for of Web API MSCRM 2016
exmaple of ODATA
https://URL/accounts?$select=name&$expand=primarycontactid($select=contactid%20,fullname)%20&$filter=primarycontactid/contactid%20eq%20contactId
List accounts starting with A and C
var qry = “accounts?$filter=startswith(name,’A’) or startswith(name,’C’)”;
List accounts owned by a particular user
var qry = “accounts?$select=name,accountnumber,_primarycontactid_value,createdon,accountcategorycode,revenue&$filter=_ownerid_value
Read account details along with the primary contact phone.
We need to use the $expand clause to request data of related entity. However it appears that the $expand clause only works when requesting data of a single record as shown in the below query.
List all Phone Calls of an account
This will display only the subject of the related phone calls.
1 | function WhoAmIRequest() { |
2 | var clientUrl = Xrm.Page.context.getClientUrl(); |
3 | var req = new XMLHttpRequest() |
4 | req.open( "GET" , encodeURI(clientUrl + "/api/data/v8.0/WhoAmI()" ), 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 ) { |
11 | req.onreadystatechange = null ; |
12 | if ( this .status == 200) { |
13 | var data = JSON.parse( this .response); |
14 | alert( "User Id : " +data.UserId+ "\nBusiness Unit Id : " +data.BusinessUnitId+ "\nOrganization Id : " +data.OrganizationId); |
18 | var error = JSON.parse( this .response).error; |
No comments:
Post a Comment