RE: Need to add button in ribbon
So you have a button, for that button to be visible it needs a command.
go to the command for your button (if you don't have one then create one). Then where I've put a 1, click add action and make sure you select JavaScript action. You're going to want a JavaScript function that you can reference from the ribbon workbench ( 2 = web resource where the JavaScript lives, 3 = function you want to use)
function example() {
debugger;
//update
var clientURL = Xrm.Page.context.getClientUrl();
var recordId = Xrm.Page.data.entity.getId();
var req = new XMLHttpRequest();
req.open("PATCH", encodeURI(clientURL + "/api/data/v8.1/incidents(DC9E62A8-90DF-E311-9565-A45D36FC5FE8)", true)); //replace this guid with recordId
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");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204) {
alert("success");
}
else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send(JSON.stringify(
{
statecode: 0,
statuscode: 1
}));
}