Friday, April 29, 2016

How to retrieve data in web api in crm 2016

function Retrievedata()
{
var GUIDvalue = Xrm.Page.data.entity.getId();
alert(GUIDvalue);
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts("+GUIDvalue.slice(1, -1)+")?$select=accountnumber", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            var accountnumber = result["accountnumber"];
alert(accountnumber);
        }
        else {
            alert(this.statusText);
        }
    }
};
req.send();
}



2 comments:

  1. Useful information. Fortunate me I found your site by accident, and I’m shocked why this coincidence didn’t came about in advance! I bookmarked it.
    ios game development

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete