send the task to approval center using JSOM Project Online
-
11-12-2020 - |
Question
I have found many scripts on the internet on how to update a task using JSOM, but through JSOM i am able to only checkout, checkin and publish. The task doesnt go to approval center. Is there a way to do it?
Solution
I was able to crack it. Below is a sample code. Note (Its not clean but hope you all can understand :P) We need to use Enterprise Resource Entity to get the assignment. Then use submitStatusUpdates which will send it to the approval center
function runMyCode() {
//Create the ProjectContext object
projContext = new PS.ProjectContext('PWA Site Here');
enterpriseresources =PS.EnterpriseResource.getSelf(projContext);
assignments = enterpriseresources.get_assignments();
projContext.load(assignments);
projContext.executeQueryAsync(LoadProject, QueryFailed);
}
function LoadProject() {
//Create variable that will hold specific project information
assignment = assignments.getByGuid($.urlParam('AssignmentID'));
projContext.load(assignment);
projContext.executeQueryAsync(GetTasks, QueryFailed);
}
function GetTasks() {
assignment.set_comments($("#taskcomments").val());
assignment.set_item('Custom Field Internal Name',parseInt(percentComplete));
assignment.set_actualStart(actualstartdateformat.toISOString()); //actualStart
assignment.set_actualFinish(actualenddateformat.toISOString()); //actualFinish
assignment.submitStatusUpdates("");
projContext.executeQueryAsync(PublishAndCheckIn, QueryFailed);
}
function PublishAndCheckIn(response) {
alert("Updated");
console.log(response);
}
function QueryFailed(error)
{
alert("Failed");
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange