In this blog, we are going to learn how to add list item into SharePoint List using Jsom/JavaScript.
Step 1: Create a list named "Info" with two-column named Name and Address.
Step 2: Get the value of your HTML control and use this code to add an item.On Place of the "XYZ" pass value of your control.
var ctx = new SP.ClientContext("URL of your site");
var oList = ctx.get_web().get_lists().getByTitle('Info');
var createiteminfo = new SP.ListItemCreationInformation();
this.ListItem = oList.addItem(createiteminfo);
ListItem.set_item('Name',"xyz");
ListItem.set_item('Address',"xyz");
ListItem.update();
ctx.load(ListItem);
ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
On the success of this function, it calls onQuerySucceeded() function and when it throws some exception onQueryFailed() function will be called.
function onQuerySucceeded()
{
alert("Item is created.")
}
function onQueryFailed(sender, args)
{
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
Happy Coding !!!
Step 1: Create a list named "Info" with two-column named Name and Address.
Step 2: Get the value of your HTML control and use this code to add an item.On Place of the "XYZ" pass value of your control.
var ctx = new SP.ClientContext("URL of your site");
var oList = ctx.get_web().get_lists().getByTitle('Info');
var createiteminfo = new SP.ListItemCreationInformation();
this.ListItem = oList.addItem(createiteminfo);
ListItem.set_item('Name',"xyz");
ListItem.set_item('Address',"xyz");
ListItem.update();
ctx.load(ListItem);
ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
On the success of this function, it calls onQuerySucceeded() function and when it throws some exception onQueryFailed() function will be called.
function onQuerySucceeded()
{
alert("Item is created.")
}
function onQueryFailed(sender, args)
{
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
Happy Coding !!!
Comments
Post a Comment