I've been reading a lot of these posts to try and figure things out but still have some questions.
The sequence of events is Edit screen displays, user enters data, and submits(I have omitted that code on purpose as it works). On the submit new list item is created in list 2 with some info from the from and from list 1. Then list 1 is updated.
My code has three ExecuteQueryAsync blocks. Get info from list1, Create new item in list 2(from list 1 and user input), and update item in List 1 (from user input). There may be (and probably is) an easier way but I'm new so there you go. Using promises to process these.
Thanks so much in advance. This is driving me crazy to get this far and not have it work.
It is the last item (update) that is not firing which you can see at the second .then. At the moment the UpdateListItem has no code as I was testing to see if it would fire. Once I understand and get that part to fire I plan to put the async code to process.
function GetSomeData(ItemID, siteURL, srcListName, IntNames, srcFieldVals, tInternalNames) {
GetListItem(ItemID, siteURL, srcListName, IntNames, srcFieldVals, tInternalNames)
.done(function (mylist) {
srcFieldVals['ProjName'] = mylist.get_item(IntNames['ProjName']);
$("#lemydateold").text(srcFieldVals['LE'].toLocaleDateString('en-us'));
})
.then(function (mylist) { // Updates target list (shedule test)
console.log(' then completed');
NewSchedListItem(mylist, IntNames, tInternalNames);
})
.then(function (mylist) { //THIS BLOCK DOES NOT FIRE
UpdateListItem(mylist);
}))
};
function GetListItem(myID, siteURL, srcListName) {
var ctx = new SP.ClientContext(siteURL);
console.log('Get List Item Handler');
this.list = ctx.get_web().get_lists().getByTitle(srcListName);
this.listitem = list.getItemById(myID);
ctx.load(listitem);
ctx.executeQueryAsync(
this.OnSuccessGet.bind(this),
this.OnFailGet.bind(this),
);
return deferred.promise();
};
function OnSuccessGet(sender, args) {
deferred.resolve(listitem);
}
function OnFailGet(sender, args) {
deferred.reject(sender, args);
}
function NewSchedListItem(srclistitem, srcIntNames, tIntNames) {
var ctxNew = new SP.ClientContext("https://someurl.com");
var tlist = ctxNew.get_web().get_lists().getByTitle('Schedule-TEST');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.tListItem = tlist.addItem(itemCreateInfo);
tListItem.set_item(tIntNames['ProjName']), srclistitem.get_item(srcIntNames['ProjName']);
tListItem.Update();
ctxNew.load(tlistitem);
ctxNew.executeQueryAsync(
this.OnSuccessNewSched.bind(this),
this.OnFailNewSched.bind(this),
);
return deferred.promise();
};
function OnSuccessNewSched(sender, args) {
deferred.resolve(listitem);
}
function OnFailNewSched(sender, args) {
deferred.reject(sender, args);
}
function UpdateListItem(mylist){
console.log('at update list function');
}
function GetItemID(mylink){
var myid=mylink.substring(mylink.indexOf("?")+1,mylink.indexOf("&"));
var ItemID=myid.substring(myid.indexOf("=")+1);
return ItemID;
}