Tuesday, 11 March 2014

How to get new item ID of the sharepoint using Javascript

How to get new item ID of the sharepoint using Javascript
function createNewListItem() {
var ctx = new SP.ctx.get_current();
var oList = ctx.get_web().get_lists().getByTitle('Test');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', "Hello");
oListItem.update();
ctx.load(oListItem);
ctx.executeQueryAsync(Function.createDelegate(this, this.onCreateSucceeded), Function.createDelegate(this, this.onCreateFailed));
}
function onCreateSucceeded() {
alert('Item created: ' + oListItem.get_id());
// You will get New item id : oListItem.get_id()
//Or

alert('Item created: ' + oListItem.get_item("ID"));
}
function onCreateFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}