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

Read only field , get latest value from read only field in in power app portal

Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...