Update Project Task in Project Online Using CSOM

Update Project Task in Project Online Using CSOM

Update Project Task in Project Online Using CSOM. In this post, you learn Update Project Task in Project Online Using CSOM and also update actual start date, Finish Date, Total Work, Percentage Complete etc using CSOM. Also, update multiple tasks with only one project publish Using CSOM. So below is complete code to Programmatically update Project task using CSOM in Project Online.

If you don’t know to add references in your solutions then follow the post below

Add  references in Solution

[AdSense-A]

using (PRCLNT.ProjectContext ProjectCont = new PRCLNT.ProjectContext(OnlinePWA))//PWA Url
            {
                SecureString passWord2 = new SecureString();
                foreach (char c in Passwords.ToCharArray()) passWord2.AppendChar(c);
                ProjectCont.Credentials = new SharePointOnlineCredentials(UserName, passWord2);
                ProjectCont.Load(ProjectCont.Projects,
                 c => c.IncludeWithDefaultProperties( pr => pr.Assignments, pr => pr.FinishDate, pr => pr.Tasks,  pr => pr.PercentComplete, pr => pr.ProjectResources));
                ProjectCont.ExecuteQuery();
                var projCollection = ProjectCont.LoadQuery(ProjectCont.Projects.Where(p => p.Name == "P1"));
                ProjectCont.ExecuteQuery();
                PublishedProject proj2Edit = projCollection.First();
                DraftProject pp = proj2Edit.Draft;
                JobState state = ProjectCont.WaitForQueue(pp.CheckIn(true), 20);
                DraftProject projCheckedOut = proj2Edit.CheckOut();
                ProjectCont.Load(projCheckedOut.Tasks);
                ProjectCont.ExecuteQuery();
                DraftTaskCollection tskcoll = projCheckedOut.Tasks;
                foreach (DraftTask tsk in tskcoll)
                {                   
                            tsk.ActualStart = Convert.ToDateTime("ActualStart");                       
                            tsk.ActualFinish = Convert.ToDateTime("ActualFinish");                       
                            tsk.Work = "Work";                       
                            tsk.ActualWork = "ActualWork";                      
                            tsk.PercentComplete = Convert.ToInt32("PercentComplete");                      
                }

                projCheckedOut.Publish(true);
                QueueJob qJob = ProjectCont.Projects.Update();
                ProjectCont.WaitForQueue(qJob, 20);
                
            }

 


Comments

  1. Thank you for the example. I use a similar code to change the value of another field Start. In this case, the code works, but in the draft and published version of the project, the field Start takes a value in which the date and month are reversed. Tell me please, how to solve this problem?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!