Monday, 5 February 2018

how to retrieves all the child contacts of the account using JavaScript and web API in Dynamic CRM

 how to retrieves all the child contacts of the account using JavaScript and web API in Dynamic CRM

Description:

In this example we explain that how to get or retrieve Multiple records using web API in Dynamic CRM.or how to retrieves all the child contacts of the account using JavaScript and web API in Dynamic CRM.or how to retrieve multiple 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. When we retrieving multiple records request will be similar to single record but we need to specify the filter criteria using $filter.

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

function retireveAllChildContacts() {
    var parentAccountId = Xrm.Page.getAttribute('parentcustomerid').getValue();
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/contacts?$select=accountrolecode,firstname,fullname,gendercode,lastname,middlename,_ownerid_value&$filter=_accountid_value eq " + parentAccountId + ""false);
    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.setRequestHeader("Prefer""odata.maxpagesize=10");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                for (var i = 0; i < results.value.length; i++) {
                    var accountrolecode = results.value[i]["accountrolecode"];
                    var accountrolecode_formatted = results.value[i]["accountrolecode@OData.Community.Display.V1.FormattedValue"];
                    var firstname = results.value[i]["firstname"];
                    var fullname = results.value[i]["fullname"];
                    var gendercode = results.value[i]["gendercode"];
                    var gendercode_formatted = results.value[i]["gendercode@OData.Community.Display.V1.FormattedValue"];
                    var lastname = results.value[i]["lastname"];
                    var middlename = results.value[i]["middlename"];
                    var _ownerid_value = results.value[i]["_ownerid_value"];
                    var _ownerid_value_formatted = results.value[i]["_ownerid_value@OData.Community.Display.V1.FormattedValue"];
                }
            }
            else {
                alert(this.statusText);
            }
        }
    };
    req.send();
}


0 comments:

Post a Comment