none
Update a task using CSOM RRS feed

  • Question

  • Hi everyone,

    I want to modify a specified task using CSOM into C#.

    So i developed a method that can do the work but no modifications are made after calling this method.

    This is the code that i am using:

    using (csom.ProjectContext cc = new csom.ProjectContext(pwaPath))
                {
    
                    cc.Load(cc.Projects,
                    c => c.Where(p => p.Id == guidIdProject).IncludeWithDefaultProperties(
                        pr => pr.StartDate, pr => pr.Id, pr => pr.ProjectResources, pr => pr.Assignments, pr => pr.FinishDate, pr => pr.Owner.LoginName, pr => pr.Tasks, pr => pr.ProjectSiteUrl, pr => pr.PercentComplete, pr => pr.ProjectResources, pr => pr.CustomFields, pr => pr.EnterpriseProjectType
                        )
                    );
                    cc.ExecuteQuery();
    
                    foreach (csom.PublishedProject pubProj in cc.Projects)
                    {
    
                        csom.DraftProject projCheckedOut = pubProj.CheckOut();
    
                        var tasks = projCheckedOut.Tasks;
                        var draftProject = pubProj.CheckOut();
                        cc.Load(draftProject.Tasks, c => c.Where(field => field.Id == guidIdTask));
    
                        cc.ExecuteQuery();
    
                        foreach (var task in draftProject.Tasks)
                        {
                            task.Start = Convert.ToDateTime(txtDateStart.Text);
                            task.Finish = Convert.ToDateTime(txtDateFinish.Text);
    
                        }
                        projCheckedOut.Publish(true);
                        csom.QueueJob qJob = cc.Projects.Update();
                        csom.JobState jobState = cc.WaitForQueue(qJob, 200);
                    }
                }

    Do you have a solution?

    Thank you,




    • Edited by Najar Anouar Thursday, October 20, 2016 10:20 AM
    Wednesday, October 19, 2016 3:07 PM

All replies

  • Hello,

    I have some news, with this code, i can modify the task but not all the attributes.

    For example, when i m trying to modify the name of the task, or the start date, or end date nothing change. 

    I tried to modify the percentComplete and it works, so i don't understand what is the issue here...

    using (csom.ProjectContext ProjectCont1 = new csom.ProjectContext(pwaPath))//PWA Url
                {
                    var projCollection = ProjectCont1.LoadQuery(
                    ProjectCont1.Projects
                     .Where(p => p.Id == guidIdProject));
                    ProjectCont1.ExecuteQuery();
                    csom.PublishedProject proj2Edit = projCollection.First();
                    csom.DraftProject projCheckedOut = proj2Edit.CheckOut();
                    ProjectCont1.Load(projCheckedOut.Tasks);
                    ProjectCont1.ExecuteQuery();
                    csom.DraftTaskCollection tskcoll = projCheckedOut.Tasks;
                    foreach (csom.DraftTask Task in tskcoll)
                    {
                        if ((Task.Id != null) && (Task.Id == guidIdTask))
                        {
    
                            ProjectCont1.Load(Task.CustomFields);
                            ProjectCont1.ExecuteQuery();
                            Task.Name = txtTache.Text;
                            Task.Start = DateTime.Today;
                            Task.PercentComplete = 100;
                            csom.AssignmentCreationInformation r = new csom.AssignmentCreationInformation();
                            r.Id = Guid.NewGuid();
                            r.TaskId = Task.Id;
                            Task.Assignments.Add(r);
                        }
                    }
                    projCheckedOut.Publish(true);
                    csom.QueueJob qJob = ProjectCont1.Projects.Update();
                    csom.JobState jobState = ProjectCont1.WaitForQueue(qJob, 20);
                }


    • Edited by Najar Anouar Wednesday, October 26, 2016 2:39 PM
    Wednesday, October 26, 2016 2:38 PM