0

I am creating an item in JSOM, SharePoint Designer 2013 for SharePoint on premise, and the same code that works fine for SharePoint online clients is not working fine now it keeps returning ID -1 for the newly created item:

function SAVE(){
    var clientContext = new SP.ClientContext();
    var oList = clientContext.get_web().get_lists().getByTitle('LIST NAME');

    var itemCreateInfo = new SP.ListItemCreationInformation();
    oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('Title', 'Title field');     
    oListItem.update();
    clientContext.load(oListItem);
    clientContext.executeQueryAsync(onAddSucceeded,onAddFailed);
}

function onAddSucceeded(sender, args) {
    var newItemId = oListItem.get_id();  //get Id of newly create item
    alert('pass ' + newItemId);
}

function onAddFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
  • I could not reproduce your issue with your code. – Amos_MSFT Sep 29 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.