Update SharePoint List Item using Rest API and HTML Input Element

3.7k views Asked by At

I am having a difficult time trying to get my below script to work for updating items on my SharePoint list “ProjectTracker”. I researched and tried several similar methods, but I can’t seem to get the any script version to update the list item(s). I continually receive the SharePoint error message “value”: This type SP.ListItemEntityCollection does not support HTTP PATCH method.” Statue”:400,”statusText”:”Bad Request”}. I included a screen grab of the error and below is the script I am using.

Any help or advice will be greatly appreciated. Thank you in advance.

Screen Grab of Error Message

jQuery(document).on("click", '#UpdateListItem', function(){
 UpdateListItem();
});//Button close

function UpdateListItem() {
 var myID = $("#itemID").val();
 var listName = "ProjectTracker";
 var office = $("#uOffice").val();
 var title = $("#uProjectTitle").val();
 var priority = $("#uPriority").val();
 var startDate = $("#uStartDate").val();
 var assignedTo = $("#uAssignedTo").val();
 var status = $("#uStatus").val();
 var requestor = $("#uRequestor").val();
 
 var item = {
 "__metadata": { "type": "SP.Data.ProjectTrackerListItem" },
 "Office": office,
 "ProjectTitle": title,
 "Priority": priority,
 "StartDate": startDate,
 "AssignedTo": assignedTo,
 "Status": status,
 "Requestor": requestor
 };
 
 $.ajax({
 url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + myID + ")",
 type: "POST",
 data: JSON.stringify(item),
 headers: {
     contentType: "application/json;odata=verbose",
     "Accept": "application/json;odata=verbose",
     "X-RequestDigest": $("#__REQUESTDIGEST").val(),
     "IF-MATCH": "*",
     "X-HTTP-Method":"MERGE",
 },
 success: onSuccess,
error: onError
});
function onSuccess(data) {
alert('List Item Updated');
}
function onError(error) {
alert(JSON.stringify(error));
}
}//Function close
1

There are 1 answers

1
Man Shah On

Please check list internalname and column internal name

For more details with AJAX call refer below age for full ajax call l.

https://sharepointmasterhub.blogspot.com/2020/12/sharepoint-crud-operations-with-rest-api.html?m=1#Update