Sunday 4 February 2018

Retrieve another entity record by using GUID of that record in Javascript

Retrieve another entity record by using GUID of that record in Javascript


Description:

In this example we explain that how to get or retrieve single records using web API in Dynamic CRM.or how to retrieve records using JavaScript in Dynamic CRM.or using JavaScript to retrieve the records of the Dynamic CRM entity based on the id of the entity. Or retrieve the another entity record by using GUID of that record in JavaScript.

So here we demonstrate that how to retrieve record from the Dynamic CRM based on the GUID of the entity using JavaScript.
Code:

var contactId = Xrm.Page.data.entity.getId();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/contacts("+contactId +")?$select=accountrolecode,fullname,gendercode"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.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            var accountrolecode = result["accountrolecode"];
            var fullname = result["fullname"];
            var gendercode = result["gendercode"];
        }
        else {
            alert(this.statusText);
        }
    }
};
req.send();



0 comments:

Post a Comment