In this post, I will explain how to delete list item in SharePoint list using ECMA script. To delete list item, firstly use getItemById (ID) function to fetch item to be deleted and then call deleteObject () to delete list item.
<script type="text/ecmascript">
function DisplayListItems()
{
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Employees');
this.oListItem = oList.getItemById(3);
oListItem.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this,this.OnSuccess), Function.createDelegate(this, this.OnFailure));
}
function OnSuccess()
{
alert('Item deleted successfully');
}
function OnFailure(sender, args)
{
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
No comments:
Post a Comment