Project CSOM can not add a new task request if the enterprise resource pool contains more than 1000

New Contributor

I use the following code to add a new task request through CSOM on Project Server 2019:

 

        var resources = projectContext.LoadQuery(projectContext.EnterpriseResources.Where(n => n.Name == username));
        projectContext.ExecuteQuery();

        var resource = resources.ElementAtOrDefault(0);

        StatusAssignmentCreationInformation creationInformation = new StatusAssignmentCreationInformation();
        creationInformation.ProjectId = projectGuid;
        creationInformation.Comment = "new task";

        creationInformation.Task = new StatusTaskCreationInformation() { Name = "New Task" };
        creationInformation.Task.Start = DateTime.Now;
        creationInformation.Task.Finish = DateTime.Now.AddDays(7);
        resource.Assignments.Add(creationInformation);
        resource.Assignments.Update();
        resource.Assignments.SubmitAllStatusUpdates("new task");

        projectContext.ExecuteQuery();

 

It works if a project server contains < 1000 enterprise resources. In another case, it generates the following error on the last projectContext.ExecuteQuery() step:

 

Too many resources: 1132. You cannot load dependent objects for more than 1000 resources. Use a filter to restrict your query.

 

However, the code does not contain any query of 1132 resources (only 1 resource on the first line).

How can I resolve this issue?

 

0 Replies