In this blog, wanna discuss about updating the task predecessor along with the Lead/Lag time using CSOM.
I had gone through a scenario where I need to repeat a phase for ‘n’ n.of times (as per the user input) and need to update all the relevant custom fields along with Predecessors as well. Assume that generating ‘n’ no.of SPRINT phases while creating the project plan.
Was able to GET & SET the Predecessor task id, dependence type but struggled to get & set Lead/Lag time. The reason is I’ve used old CSOM DLLs which doesn’t have the “Link lag duration” property. It was released by Microsoft in the month of October 2019 as part of the SharePoint 2019 security updates. you can find the MS security update release post at the below link.
Was able to get & set the “Lead/Lag” time after updating my CSOM DLLs. My current CSOM DLLs version is 16.1.19724.12000
If we closely look at the predecessor value it has 3 combinations.
We have task properties to read the Task Predecessor Start ID and End ID, Dependency type and LinkLagDuration (to read Lead or Lag time) in the CSOM DLLs.
In the LinkLagDuration, the negative value indicates Lead time and positive value indicates Lag time.
Below is the snippet code to create and update the predecessor value of a task.
//Create a Task Links TaskLinkCreationInformation taskLink = new TaskLinkCreationInformation(); taskLink.Id = Guid.NewGuid(); taskLink.DependencyType = task.Predecessors.FirstOrDefault().DependencyType; taskLink.LinkLagDuration = task.Predecessors.FirstOrDefault().LinkLagDuration; taskLink.StartId = predecessorTaskLinkId; taskLink.EndId = currentTaskGuid; draft.TaskLinks.Add(taskLink);