Sunday 10 January 2016

Change Record Status in CRM 2016 through Webapi in javascript

In the below code i am deactivating account record to Inactive


function decativateRecordThroughWebapi() {

    var entityId = Xrm.Page.data.entity.getId();
    var clientURL = Xrm.Page.context.getClientUrl();
    entityId = entityId.replace("{","");
    entityId = entityId.replace("}", "");

    var req = new XMLHttpRequest();
    var odataQuery = encodeURI(clientURL + "/api/data/v8.0/accounts(" + entityId + ")");
    req.open("PATCH", odataQuery, false);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    //Parameters
    var account = {};
    account["statecode"] = 1; // State code value
    account["statuscode"] = 2; //  status reason Value

    req.send(JSON.stringify(account));

    if (req.readyState == 4) {
        if (req.status == 204) {

            alert("Success");
        } else {
            var error = JSON.parse(req.response).error;
            alert(error.message);
        }

    }

}

No comments:

Post a Comment

Numbering Table Parent group and child group ssrs report

 Recently I have faced a scenario to numbering parent group and subgroup in the following formate 10 parentGroupRow1    10.1 childGroupRow1 ...