0

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
TonyT
  • 407
  • 4
  • 19
  • 1
    The error shows that you're trying to update an item collection, not a single item. Can u use F12 to trace the real request? – Baker_Kong Nov 24 '20 at 01:44
  • Thank you for your reply but I'm not sure how to trace this issue through F12. Any advice how to accomplish this action? – TonyT Nov 24 '20 at 02:51
  • 1
    It's Browser F12 tool. Go to network tab to see the behind request. it should provide more info https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide/network – Baker_Kong Nov 24 '20 at 04:34
  • I followed your directions and located the issue. My list name showed a space in it, SP.Data.Project TrackerListItem, even though it's not showing that way on the list. But when I tweak my script (list name) filling the space like the following, SP.Data.Project_x0020_TrackerListItem, everything worked (updated as expected). Something so small caused so much of a headache. But all is good now. Thank you so much for the advice...very helpful! – TonyT Nov 24 '20 at 06:10
  • That's really good ! – Baker_Kong Nov 24 '20 at 06:21

1 Answers1

-1

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

  • Welcome to Stackoverflow! Please use tags to categorize your post. Also explain what you have tried and what exactly your problem is. Without explaining this in detail, we can only guess what you want. Linking to some blog post does not make this requirement obsolete. – rugk Dec 19 '20 at 14:19