I'm currently trying to get the id of my currently iserted item. I'm making a timesheet which user is able to save and retrieve his own timesheet. The thing is that i put the ID of an item in the html code so i know if the item is coming from my list or if it was currently inserted by the user . So i want to know the currently inserted item and put it in my html code so i know that it has been inserted in the list and i have to make an update of that item and not insert it a second time.
Here is how i'm saving/updating current user timesheet
if ($(this).find("input").attr("data-ID")) {
updateTimesheet($(this).find("input").attr("data-ID"), jobCode, prestation, parseFloat($(this).find("input").val()), dateMonth);
}
else {
entry = webList.addItem(entryCreationInformation);
entry.set_item("JobCode", jobCode);
entry.set_item("ClientName", prestation);
entry.set_item("DateMonth", dateMonth);
entry.set_item("Heure",heure);
entry.update();
context.load(entry);
context.executeQueryAsync(success, fail);
}
function success() {
//do nothing
}
function fail(sender, args) {
alert("Call failed. Error: " +
args.get_message());
}
function updateTimesheet(id,jobCode,clientName,heure,date) {
var clientContext = context;
var oList = webList;
this.oListItem = oList.getItemById(parseInt(id));
oListItem.set_item("JobCode", jobCode);
oListItem.set_item("ClientName", clientName);
oListItem.set_item("DateMonth", date);
oListItem.set_item("Heure", heure);
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
//alert('Item updated!');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
I've tried like getting the entry.ID on query success but it doesn't work. I've also tried to get the id just after the context.exectureQueryAsync in case the entry was updated but doesn't work either.
I tried this solution here: http://social.technet.microsoft.com/Forums/sharepoint/en-US/d9c68caa-ddfd-4a68-a32f-d6154546f42e/getting-id-of-newly-inserted-item-with-silverlight?forum=sharepointdevelopmentprevious but won't work too.
I'm learning Sharepoint on the job so maybe it isn't best solution to do this.
Thank you in advance.