This is exactly what I want to accomplish, given below are the steps I'm performing.
- Update sub task status based on subTaskId (SP Task List), using executeQueryAsync()
- Get all sub tasks based on taskId using SP REST API
- Based on all sub task status accordingly update task status using executeQueryAsync()
Problem statement : Here I'm dealing with back to back async function calls and in 2nd step I'm not getting the latest updated sub-tasks status. REST API gives me old sub task status and hence task status gets wrongly updated. Here's sample code structure :
calling function(){
saveSubTaskStatus(subTaskId);
fetchAllSubTasks(); //REST api
updateTaskStatusAccordingly(taskId);
}
saveSubTaskStatus(subTaskId){
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded(sender, args) {
//fetchAllSubTasks(); //REST api
//Some business logic
//updateTaskStatusAccordingly(taskId);
}
function updateTaskStatusAccordingly(taskId){
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
Executing on call back functions is not working. I've not tried deferred/Promises JavaScript.
Other then this is there any other approach to accomplish the above tasks.