-1

I am using an old SharePoint 2010 product.

Inside my site, I created a Status list which looks like this:

Status list

I found some Web Service API method which allows me to update some records like UpdateListItems() or UpdateList()

Can you please tell me how to build an update request to update the Status field based on the CaseNumber# field?

Draken
  • 3,134
  • 13
  • 34
  • 54
Odyn
  • 1
  • 1
  • Please check this Vadim Gremyachev reply at https://stackoverflow.com/questions/17820779/sharepoint-2010-rest-api-jquery-insert-update-delete – Gary Deol Aug 14 '19 at 12:32

1 Answers1

0

We can use listdata.svc to update list item based on the casenumber field. The following example code for your reference, modify the variables and add the code into a content editor web part, click the button to update list item.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function updateListItem() {
    var siteUrl="http://sp2010";
    var listName="StatusList";
    var caseNumber="456798";
    var itemProperties={
        'Status': 'Approval'
    };
    $.ajax({
        url: siteUrl + "/_vti_bin/listdata.svc/"+listName+"?$filter=CaseNumber eq '"+caseNumber+"'",
        type: "GET",
        headers: {
            "Accept": "application/json;odata=verbose",
        },
        success: function (data) {          
            var item=data.d.results[0];
            $.ajax({
                type: 'POST',
                url: item.__metadata.uri,
                contentType: 'application/json',
                processData: false,
                headers: {
                    "Accept": "application/json;odata=verbose",
                    "X-HTTP-Method": "MERGE",
                    "If-Match": item.__metadata.etag
                },
                data: Sys.Serialization.JavaScriptSerializer.serialize(itemProperties),
                success: function (data) {
                    alert("succeeded."); 
                },
                error: function (data) {
                    alert(JSON.stringify(data));
                }
          });
        },
        error: function (err) {
            console.log(JSON.stringify(err));
        }
    });
}
</script>
<input type="button" value="update list item" onclick="updateListItem()"/>

enter image description here

LZ_MSFT
  • 4,079
  • 1
  • 8
  • 9