SharePoint Online Add Update Delete Item from List using SPServices

This SharePoint Online tutorial I will explain, how to insert, update and delete items from SharePoint list using SPServices.js in SharePoint Online in Office 365.

If you are new to SPServices in SharePoint 2013, read Work with SPServices in SharePoint 2013/2016/Online.

Add an item to a SharePoint Online list item using SPServies

Below is the code to Add an item to a SharePoint list item using SPServies. You can add the below code inside a script editor web part or in a content editor web part in SharePoint Online.

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<script type=”text/javascript” src=”//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js”></script>

<script type=”text/javascript” language=”javascript”>
$(document).ready(function() {
var title=”My Test Item”;
AddNewListItem(title);
});
function AddNewListItem(title)
{
$().SPServices({
operation:”UpdateListItems”,
async: false,
batchCmd: “New”,
listName: “TestList”,
valuepairs:[[“Title”,title]],
completefunc:function(xData, Status)
{
alert(“Item inserted”);
}
});
}
</script>
The item will appear like below:

SharePoint Online Add Update Delete Item from List using SPServices

SharePoint Online Add Update Delete Item from List using SPServices

Update SharePoint Online List Item using SPServices:

To update an item we need the item id. Below is the code to update a list item using SPServices in SharePoint Online.

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<script type=”text/javascript” src=”//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js”></script>

<script type=”text/javascript” language=”javascript”>
$(document).ready(function() {
var title=”My Test Item – Updated”;
UpdateListItem(title);
});
function UpdateListItem(title)
{
$().SPServices({
operation:”UpdateListItems”,
async: false,
batchCmd: “Update”,
listName: “TestList”,
ID: 3,
valuepairs:[[“Title”,title]],
completefunc:function(xData, Status)
{
alert(“Item Updated”);
}
});
}
</script>
The item title will be updated like below:

SharePoint Online Add Update Delete Item from List using SPServices

SharePoint Online Add Update Delete Item from List using SPServices

Delete SharePoint Online List Item using SPServices:

Like Edit an item, to delete an item also we need the item id. Below is the code to delete a list item using SPServices in SharePoint Online.

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<script type=”text/javascript” src=”//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js”></script>

<script type=”text/javascript” language=”javascript”>
$(document).ready(function() {
DeleteListItem();
});
function DeleteListItem()
{
$().SPServices({
operation:”UpdateListItems”,
async: false,
batchCmd: “Delete”,
listName: “TestList”,
ID: 3,
completefunc:function(xData, Status)
{
alert(“Item Deleted”);
}
});
}
</script>

We have three items and after this code execute the last item got deleted like below:

SharePoint Online Add Update Delete Item from List using SPServices

SharePoint Online Add Update Delete Item from List using SPServices

You may like following SPServices SharePoint 2013/2010 tutorials:

Hope this SharePoint SPServices tutorial explains how to do insert, update and delete operation in SharePoint Online using SPServices.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

>