In this blog, we are going to learn how to update the SharePoint list item using the JSOM.
To update the SharePoint list item or delete it, we can do this using the help of item id.
Here we are performing an operation on the list named "Info", which have two columns "Name" and "Address". Replace "***.sharepoint.com" with your tenant URL and replace the ListItemID with your item id.
var clientContext = new SP.ClientContext('***.sharepoint.com');
var oList = clientContext.get_web().get_lists().getByTitle('Info');
var oListItem = oList.getItemById(listItemID);
oListItem.set_item('Name','xyz');
oListItem.set_item('Address','xyz');
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.ItemUpdate), Function.createDelegate(this, this.onQueryFailed));
function ItemUpdate(){
alert('Item updated');
}
function onQueryFailed(sender,args){
alert('Request failed. ' + args.get_message() + '\n'+args.get_stackTrace());
}
after successful execution of the function, it calls the ItemUpdate() function and when it get failed it throws an exception.
Happy Coding!!!!!
To update the SharePoint list item or delete it, we can do this using the help of item id.
Here we are performing an operation on the list named "Info", which have two columns "Name" and "Address". Replace "***.sharepoint.com" with your tenant URL and replace the ListItemID with your item id.
var clientContext = new SP.ClientContext('***.sharepoint.com');
var oList = clientContext.get_web().get_lists().getByTitle('Info');
var oListItem = oList.getItemById(listItemID);
oListItem.set_item('Name','xyz');
oListItem.set_item('Address','xyz');
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.ItemUpdate), Function.createDelegate(this, this.onQueryFailed));
function ItemUpdate(){
alert('Item updated');
}
function onQueryFailed(sender,args){
alert('Request failed. ' + args.get_message() + '\n'+args.get_stackTrace());
}
after successful execution of the function, it calls the ItemUpdate() function and when it get failed it throws an exception.
Happy Coding!!!!!
Comments
Post a Comment