Created
March 22, 2014 08:57
-
-
Save vgrem/9703429 to your computer and use it in GitHub Desktop.
Update operation in SharePoint 2010 REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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