Monday 8 May 2017

Update SharePoint list item using REST API

Solution:

Here I create 2 variables as follow:

1)      url : REST API with list name
2)      data : this variable contain the column name with respective values

var url = "/_api/Web/Lists/GetByTitle('CRUDList')/getItemById('1')";
var data = {
__metadata: { 'type': 'SP.Data.CRUDListListItem' },
            Title: 'Update title'
};


Function:

function updateItem(url, updateData) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "PATCH",
headers: {
                        "accept": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                        "content-Type": "application/json;odata=verbose",
                        "X-Http-Method": "PATCH",
                        "If-Match": "*"
                    },
                    data: JSON.stringify(updateData),
                    success: function (data) {
                        console.log(data);
                    },
                    error: function (error) {
                        alert(JSON.stringify(error));
                    }
                });
            }


Function call:

updateItem(url,data);


Feel free to revert in-case of any query...


Product Applies To:

·         SharePoint Server 2013

·         SharePoint Foundation 2013


 

No comments:

Post a Comment