In this blog, I would like to add a code snippet for updating items in a SharePoint Announcement list, using JavaScript Object Model. The Client Object Model must conclude with a call to ExecuteQuery() or ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler).
Steps
  1. Open your SharePoint Site.
  2. Edit the SharePoint page and add a Content Editor WebPart.
  3. Add the following JavaScript code into CEWP.
  4. Save the page and hit F5.
Code snippet
  1. $(document).ready(function
  2. {
  3. updatelistitem();
  4. });
  5. function updatelistitem() {
  6. var clientContext = new SP.ClientContext(https://gowtham.sharepoint.com/tutorials");
  7. this.oListItem = oList.getItemById(3);
  8. var oList = clientContext.get_web().get_lists().getByTitle('Announcements');
  9. oListItem.set_item('Title', 'My Updated Title');
  10. oListItem.update();
  11. }
  12. function onQuerySucceeded() {
  13. alert('Item updated sucessfully: ' + oListItem.get_id());
  14. }
  15. function onQueryFailed(sender, args) {
  16. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  17. }