following is my code. I am trying to update a Choice ListITem (dropdownlist) in a Custom list using Rest API. I have debugged the code it goes into success handler but the Item still has the old value.
I am trying to change Status to closed. I have noticed even if I change the Status to Status1 some Field that does not exists in the list it goes to Succeess handler anyway.
var data = GetListItem(); //using Rest Api.
var newStatus = "Closed";
var name = "MyList";
var itemType = "SP.Data.MyListListItem";
var item = {
"__metadata": { "type": itemType },
"Status": newStatus
};
var t = JSON.stringify(item);
$.ajax({
url: data.__metadata.uri, //I have checked uri is "https://condev.sharepoint.com/_api/Web/Lists(guid'98b0412e-e32f-41f2-b1a4-1324ad65fce9')/Items(2)"
method: "POST",
body: JSON.stringify(item), // it is "{\"__metadata\":{\"type\":\"SP.Data.MyListListItem\"},\"Status\":\"Closed\"}"
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": data.__metadata.etag
},
success: function (data) {
alert("Project status changed to closed");
},
error: function (data, errorCode, errorMessage) {
alert("Rest Api error (upadate listitem)=" + errorMessage);
}
});