For our example, lets assume we have a campaign record and we want to update the "OtherCost" field. Here is how it is done:
// update the parent campaign with the total value
var changes = { "OtherCost": { "Value": total.toFixed(2)} };
var updateReq = new XMLHttpRequest();
var target = context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/CampaignSet(guid'" + campaignId + "')";
updateReq.open("POST", target, true);
updateReq.setRequestHeader("Accept", "application/json");
updateReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
updateReq.setRequestHeader("X-HTTP-Method", "MERGE");
updateReq.onreadystatechange = function () {
if (updateReq.readyState == 4 /* complete */) {
if (updateReq.status == 204 || updateReq.status == 1223) {
// success
}
else
{
//OMG an error occured! Do something!
}
}
};
updateReq.send(JSON.stringify(changes));
No comments:
Post a Comment