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