1

Microsoft Docs LinkPredecessors Method is described as:

public void LinkPredecessors (object Tasks, Microsoft.Office.Interop.MSProject.PjTaskLinkType Link = Microsoft.Office.Interop.MSProject.PjTaskLinkType.pjFinishToStart, object Lag);

How can I assign a Lag value to "object Lag"? The below code works to assign predecessor and task link type, however, I cannot figure out how to add the lag.

Microsoft.Office.Interop.MSProject.PjTaskLinkType LinkType;

    var p = IApp.ActiveProject;
    foreach (var y in tasksPred)
    {
        int intTaskType = Convert.ToInt32(y.RelationshipType);

        switch (intTaskType)
        {
            case 0:
                LinkType = Microsoft.Office.Interop.MSProject.PjTaskLinkType.pjFinishToFinish;
                break;
            case 1:
                LinkType = Microsoft.Office.Interop.MSProject.PjTaskLinkType.pjFinishToStart;
                break;
            case 2:
                LinkType = Microsoft.Office.Interop.MSProject.PjTaskLinkType.pjStartToFinish;
                break;
            case 3:
                LinkType = Microsoft.Office.Interop.MSProject.PjTaskLinkType.pjStartToStart;
                break;
            default:
                LinkType = Microsoft.Office.Interop.MSProject.PjTaskLinkType.pjFinishToStart;
                break;
        }

        if (y.UniqueIDPredecessor != "")
        {
           p.Tasks[Convert.ToInt32(y.UniqueID)].LinkPredecessors(p.Tasks[Convert.ToInt32(y.UniqueIDPredecessor)], LinkType);
        }
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
cchapel
  • 11
  • 1
  • You don't use Interop, that's for sure. Even MS Project uses the server's web services – Panagiotis Kanavos Feb 12 '20 at 16:00
  • Since 2013, the best way is to use the [CSOM](https://learn.microsoft.com/en-us/office/client-developer/project/client-side-object-model-csom-for-project-2013) (Client-side Object Model) from Javascript, .NET or any language that can make an HTTP call. In 2019 the older PSI web service was removed – Panagiotis Kanavos Feb 12 '20 at 16:07

1 Answers1

0

The LinkPredecessors method is expecting a string for the lag. From the docs:

A string that specifies the duration of lag time between linked tasks.

Examples of this would be:

  • "2d" for a 2-working day lag
  • "30ed" for a 30-elapsed-day lag
  • "4h" for a 4-working-hour lag
  • "3w" for a 3-working-week lag
  • "30m" for a 30-working-minute lag

Adding the "e" before the time unit makes it elapased, as in calendar days. Otherwise, lag time follow the working calendar.

Community
  • 1
  • 1
Rachel Hettinger
  • 7,927
  • 2
  • 21
  • 31