Thursday, September 21, 2017

Web API retrieve Specific Account all fields


   var customerid = ""; // Pass account guid here or get from context as per your logic.

    // replacing brackets if found in id

        customerid = customerid.replace("{", "");
        customerid = customerid.replace("}", "");



 var selectQuery = "accounts(" + customerid + ")?$select=*";
 var      selectResult =WebAPISelectVersion(selectQuery, "8.0");

       var customeraccountno = selectResult.accountnumber;
        if (customeraccountno == null || customeraccountno == "")
            throw new DOMException("Customer Id is empty");


function WebAPISelect(select, version) {
    var result = null;
    var serverUrl = Xrm.Page.context.getClientUrl();
    var oDataSelect = serverUrl + "/api/data/v"+version+"/" + select;
    console.log("oDataSelect ", oDataSelect);

    var retrieveReq = new XMLHttpRequest();
    retrieveReq.open("GET", oDataSelect, false);
    retrieveReq.setRequestHeader("Accept", "application/json");
    retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    retrieveReq.setRequestHeader("OData-MaxVersion", "4.0");
    retrieveReq.setRequestHeader("OData-Version", "4.0");
    retrieveReq.onreadystatechange = function () {
        //GetContractData(this);

        if (retrieveReq.readyState == 4) {
            if (retrieveReq.status == 200) {
                result = JSON.parse(this.responseText);

                //result = 1;

                // alert(ParentEntityId);
            }
            else { // not success
                //var error = JSON.parse(this.response).error;
                result = JSON.parse(this.responseText);
                console.log(result.message);
            }
        }
    };

    retrieveReq.send();
    return result;

}


Ali Hamza Wadood 
Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies


Asp.Net MVC (5) - Exception Filter - HandleError

Applicable on Asp.Net MVC5 HandleError Filter This belongs to Exception Filters category (Authentication Filter, Authoriz...