1

Below is the code that I use.

using (ProjectContext projContext = new ProjectContext('pwa url'))
{
   projContext.AuthenticationMode = ClientAuthenticationMode.Default;
   projContext.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
   var projects = oBasicDetails.ProjContext.Projects;
   var ProjectContext = oBasicDetails.ProjContext;
   IEnumerable<PublishedTask> publishedTasks = ProjectContext.LoadQuery(selectedProject.Tasks);
   ProjectContext.ExecuteQuery();
   foreach (PublishedTask oTTask in publishedTasks)
   {
      IEnumerable<PublishedTaskLink> oPredecessorsList = ProjectContext.LoadQuery(oTTask.Predecessors);
      ProjectContext.ExecuteQuery();
      foreach (PublishedTaskLink PredecessorTask in oPredecessorsList)
      {
      if (PredecessorTask.IsObjectPropertyInstantiated("LinkLagFmt"))
      {
          Lag = PredecessorTask.LinkLag;
      }
      if (PredecessorTask.IsObjectPropertyInstantiated("LinkLagDuration"))
      {
          Lag = PredecessorTask.LinkLag;
      }
      if (PredecessorTask.IsObjectPropertyInstantiated("LinkLag"))
      {
          Lag = PredecessorTask.LinkLag;
      }
   }
   }
   var ParentTaskId = oTTask.Parent.Id;
}

When I try to access LinkLag or Parent.Id, I get PropertyOrFieldNotInitializedException.

ProjectContext.Load()
ProjectContext.ExecuteQuery()

If this is a valid solution. What should I be loading to ProjectContext?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy