Update operation in SharePoint 2010 REST API
function updateListItem(webUrl,listName,itemId,itemProperties,success, failure) | |
{ | |
getListItemById(webUrl,listName,itemId,function(item){ | |
$.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) { | |
success(data); | |
}, | |
error: function (data) { | |
failure(data); | |
} | |
}); | |
}, | |
function(error){ | |
failure(error); | |
}); | |
} | |
//Usage: set Task Name & AssignedTo | |
var taskProperties = { | |
'TaskName': 'Approval', | |
'AssignedToId': 12 | |
}; | |
updateListItem('https://contoso.sharepoint.com/project/','Tasks',2,taskProperties,function(item){ | |
console.log('Task has been updated'); | |
}, | |
function(error){ | |
console.log(JSON.stringify(error)); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment