3

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?

  • In Project Online... there is an inbuilt approval center where incase i update any task, it goes there. But this works when i do it the OOTB way... i dont see any options for the same in JSOM – dsouzajoel22 Nov 21 '16 at 7:40
1

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");
  }
 });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.