
Hi All,
I am using below code to update an entity.
function UpdateOrphan(_formContext) {
var entityUpdate = {};
var newAcademicLevel = GetNewAcademicLevel(_formContext),
oldAcademicLevel = GetOldAcademicLevel(_formContext);
if (newAcademicLevel) {
entityUpdate[orphanFields.CurrentAcademicLevel] = newAcademicLevel;
} else if (oldAcademicLevel) {
entityUpdate[orphanFields.CurrentAcademicLevel] = null;
}
var orphan = GetOrphan(_formContext);
UpdateAndReturnUpdateStatus(entityUpdate, orphan[0].id, globalVariables.WebAPIVersion, entitys.Orphans);
}
function UpdateAndReturnUpdateStatus(entity, recordID, webAPIVersion, entitysPluralName) {
recordID = recordID.replace(/[{}]/g, "");
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/" + webAPIVersion + "/" + entitysPluralName + "(" + recordID + ")", false);//Sync
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
globalVariables.UpdateStatus = true;
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}
I am not able to set null with this code. I am receiving 204 in the return.
What is wrong in my code?
Thanks
Regards,
AW
*This post is locked for comments
I have the same question (0)Hello,
I would recommend to use fiddler to check what request is sent to server and provide correspond schreenshot here.
I'm suspicious that your code doesn't set field to null value or something on the backend sets field back - plugin or workflow.
PS FYI 204 ststus is absolutely normal response - it means that there was no data returned as a response.