After tirelessly searching through various resources and attempting different code snippets from Microsoft Documentation, I am still unable to identify my mistake. I am working on updating a field named DispatchStatus in a list called Schedule Orders using REST. Unfortunately, every attempt I make results in either an undefined success function with the field remaining unchanged or an error message like this:
{"readyState":4,"responseText":"404 NOT FOUND","statusText":"NOT FOUND"}
Here is the code I currently have:
function updateDelivery(id) {
var url = "_api/web/lists/GetByTitle('Scheduled Orders')/items(" + id + ")"
var itemMetadata = {
'__metadata': {
'type': getListItemType('Scheduled Orders')
},
'DispatchStatus': document.getElementById(id).value
};
updateL(url, itemMetadata, checkresult);
}
function updateItem(url, itemMetadata, callback) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
data: JSON.stringify(itemMetadata),
type: 'POST',
contentType: 'application/json;odata=verbose',
headers: {
'X-HTTP-Method': 'MERGE',
'X-RequestDigest': $("#__REQUESTDIGEST").val(),
'Accept': 'application/json;odata=verbose',
'IF-MATCH': '*'
},
success: function (data) {
callback(data);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
function getListItemType(name) {
var ret = "";
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + name + "')?$select=ListItemEntityTypeFullName"
$.ajax({
url: url,
method: "GET",
async: false,
headers: {
"Accept": "application/json; odata=verbose"
},
success: function (data) {
ret = data.d.ListItemEntityTypeFullName
},
error: function (error) {
alert(JSON.stringify(error));
}
});
return ret;
}
It feels like updating a list item should be a straightforward task. Am I overlooking essential data? Do I need to transfer all previous data into the item? Or should I approach item updating in a different manner?