Hi i have referred to the below link as i have experiencing the same problem. ListItem.get_id() return “-1” after adding value in custom list 2
as i was facing similar issue. but it didnt solve my problem. Please see my code, It adds the value but always returns -1 as the id.
if (Description != null && Description.length > 0) { //alert(Description.length); // var obj = { Title: oListItem.get_item('Title'), ProductName: oListItem.get_item('Product_x0020_Name'), Price: oListItem.get_item('Price') }; var clientContext = new SP.ClientContext(); var oList1 = clientContext.get_web().get_lists().getByTitle('Order'); var itemCreateInfo = new SP.ListItemCreationInformation(); this.oListItem1 = oList1.addItem(itemCreateInfo); this.oListItem1.set_item('Description', Description); this.oListItem1.set_item('OrderID', str); this.oListItem1.set_item('Total', total); this.oListItem1.set_item('Comments', Comments); this.oListItem1.set_item('RFS_x0020_Number', rfsNumber); this.oListItem1.set_item('Branch', Branch); this.oListItem1.set_item('Division', Division); this.oListItem1.set_item('Target_x0020_Location', Targetlocation); this.oListItem1.update(); document.getElementById('Text1').value = total; clientContext.load(this.oListItem1); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded5), Function.createDelegate(this, this.onQueryFailed5)); //alert(2); AddToOrderDetails(); } } function onQuerySucceeded5() { alert('Item created: ' + oListItem1.get_id()); } function onQueryFailed5(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }