I'm trying to add a new record and get the new ID created then use the new ID to create a specific reference number using the following code.
function saveDraftGHrecord() {
ghList = web.get_lists().getByTitle('Listname');
var itemCreateInfo = new SP.ListItemCreationInformation();
ghItem = ghList.addItem(itemCreateInfo);
ghItem.set_item("ReasonOther", $('#txtReasonOther').val());
etc
etc
ghItem.update();
context.load(ghList);
context.executeQueryAsync(function () {
// Success returned from executeQueryAsync
//Now we need to get the new ID and add that to ref.
var newID
newID = ghItem.get_id();
//alert(newID);
ghList = web.get_lists().getByTitle('Listname');
ghNewItem = ghList.getItemById(newID);
context.load(ghNewItem);
ghNewItem.set_item("FieldName", "REF" + newID);
ghNewItem.update();
context.load(ghNewItem);
cancelNewRecord();
}),
function (sender, args) {// Failure returned from executeQueryAsync
alert("Failure " + args.get_message());
}
}
The Record is being added an I am getting the newID using ghItem.get_id() but i cant seem to then update the same record with the new REF using ghNewItem.set_item("FieldName", "REF" + newID);
Am I missing something?