Tuesday, 21 April 2020

Update PWA Assignments

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

No comments:

Post a Comment