I am trying to create an app which posts information to a SharePoint List.
function createListItem() {
try {
var userName = document.getElementById("name").value;
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('LeaveRequest');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', userName);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
catch (err)
{
alert(err.message);
}
}
function onQuerySucceeded() {
alert('Item created Successfully! ' + oListItem.get_id());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
When I click the submit button on the form, I am getting an alert to say the item has been added and also an id for the item in the list. However when I check the list the item is not there.