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

%3CLINGO-SUB%20id%3D%22lingo-sub-2489061%22%20slang%3D%22en-US%22%3EProject%20CSOM%20can%20not%20add%20a%20new%20task%20request%20if%20the%20enterprise%20resource%20pool%20contains%20more%20than%201000%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2489061%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EI%20use%20the%20following%20code%20to%20add%20a%20new%20task%20request%20through%20CSOM%20on%20Project%20Server%202019%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%20%20%20%20%20%20%20%20var%20resources%20%3D%20projectContext.LoadQuery(projectContext.EnterpriseResources.Where(n%20%3D%26gt%3B%20n.Name%20%3D%3D%20username))%3B%0A%20%20%20%20%20%20%20%20projectContext.ExecuteQuery()%3B%0A%0A%20%20%20%20%20%20%20%20var%20resource%20%3D%20resources.ElementAtOrDefault(0)%3B%0A%0A%20%20%20%20%20%20%20%20StatusAssignmentCreationInformation%20creationInformation%20%3D%20new%20StatusAssignmentCreationInformation()%3B%0A%20%20%20%20%20%20%20%20creationInformation.ProjectId%20%3D%20projectGuid%3B%0A%20%20%20%20%20%20%20%20creationInformation.Comment%20%3D%20%22new%20task%22%3B%0A%0A%20%20%20%20%20%20%20%20creationInformation.Task%20%3D%20new%20StatusTaskCreationInformation()%20%7B%20Name%20%3D%20%22New%20Task%22%20%7D%3B%0A%20%20%20%20%20%20%20%20creationInformation.Task.Start%20%3D%20DateTime.Now%3B%0A%20%20%20%20%20%20%20%20creationInformation.Task.Finish%20%3D%20DateTime.Now.AddDays(7)%3B%0A%20%20%20%20%20%20%20%20resource.Assignments.Add(creationInformation)%3B%0A%20%20%20%20%20%20%20%20resource.Assignments.Update()%3B%0A%20%20%20%20%20%20%20%20resource.Assignments.SubmitAllStatusUpdates(%22new%20task%22)%3B%0A%0A%20%20%20%20%20%20%20%20projectContext.ExecuteQuery()%3B%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIt%20works%20if%20a%20project%20server%20contains%20%26lt%3B%201000%20enterprise%20resources.%20In%20another%20case%2C%20it%20generates%20the%20following%20error%20on%20the%20last%26nbsp%3B%3CSTRONG%3EprojectContext.ExecuteQuery()%3C%2FSTRONG%3E%26nbsp%3Bstep%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EToo%20many%20resources%3A%201132.%20You%20cannot%20load%20dependent%20objects%20for%20more%20than%201000%20resources.%20Use%20a%20filter%20to%20restrict%20your%20query.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20the%20code%20does%20not%20contain%20any%20query%20of%201132%20resources%20(only%201%20resource%20on%20the%20first%20line).%3C%2FP%3E%3CP%3EHow%20can%20I%20resolve%20this%20issue%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

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