I am working on a scenario where i want to update a record some other entity using POST method OData calls javascript.
Below is my code :
function SetAverageSalitaRating() {
try {
debugger;
if (Xrm.Page.getAttribute("sal_interpreter").getValue()) {
var interpreterId = Xrm.Page.getAttribute("sal_interpreter").getValue()[0].id;
interpreterId = interpreterId.substring(1, interpreterId.length - 1);
var ServerUrl = Xrm.Page.context.getClientUrl();
var Entity_name1 = "/api/data/v8.1/sal_interpreterses(";
var Entity_name2 = ")";
odataselect1 = ServerUrl + Entity_name1 + interpreterId + Entity_name2;
var objAccount = new Object();
objAccount.sal_salitarating = 1;
objAccount.sal_address1visit = "vivek";
var jsonEntity = window.JSON.stringify(objAccount);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataselect1,
data: jsonEntity,
async: false,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
alert("yeah");
},
success: function (data, textStatus, XmlHttpRequest) {
alert("Updated successfully");
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
}
});
}
}
catch (e) {
throw new Error(e.message);
}
}
Here my control is going inside 'success' method . Please help
*This post is locked for comments