Can't read if I have more than 20 projects
Closed this issue · 2 comments
dacheson commented
When I try to use this on a site with more than 20 projects I get an error trying to 'read' or 'manage' those projects. This is because of a hard limit in CSOM I think? Maybe you can offer a way to filter so regardless of how many I can see some.
R-Bixby commented
Xander,
The following code will get you past the limit.
// I. Get all projects (ID field) -- no project limit when default fields are retrieval items.
projContext.Load(projContext.Projects, proj => proj.Include(p => p.Id));
projContext.ExecuteQuery();
var allIds = projContext.Projects.Select(p => p.Id).ToArray();
int j = 0; //Project number (0-based)
//II. Segment the retrieval to the maximum record count returned for a query
// Calculate the number of segments to process
int numBlocks = allIds.Length / PROJECT_BLOCK_SIZE + 1;
Console.WriteLine("ProjContext count: {0}", projContext.Projects.Count());
//Get project records in blocks of 20 from the ProjOnline host
for (int i = 0; i < numBlocks; i++)
{
var idBlock = allIds.Skip(i * PROJECT_BLOCK_SIZE).Take(PROJECT_BLOCK_SIZE);
Guid[] block = new Guid[PROJECT_BLOCK_SIZE]; //Zero'd Guid Array
Array.Copy(idBlock.ToArray(), block, idBlock.Count());
var projectQuery = projContext.LoadQuery(projContext.Projects.Where(p =>
p.Id == block[0] || p.Id == block[1] ||
p.Id == block[2] || p.Id == block[3] ||
p.Id == block[4] || p.Id == block[5] ||
p.Id == block[6] || p.Id == block[7] ||
p.Id == block[8] || p.Id == block[9] ||
p.Id == block[10] || p.Id == block[11] ||
p.Id == block[12] || p.Id == block[13] ||
p.Id == block[14] || p.Id == block[15] ||
p.Id == block[16] || p.Id == block[17] ||
p.Id == block[18] || p.Id == block[19]
).Include(p => p.Id, p => p.Name, p => p.StartDate, p => p.FinishDate,
p => p.Phase, p => p.Stage, p => p.ProjectIdentifier, p => p.ProjectSummaryTask, p => p.UtilizationDate, p => p.UtilizationType));
projContext.ExecuteQuery();
etc.
…-Richard Bixby, PMP
From: Xander Harris [mailto:notifications@github.com]
Sent: Thursday, December 15, 2016 12:14 PM
To: OfficeDev/Project-Samples <Project-Samples@noreply.github.com>
Cc: Subscribed <subscribed@noreply.github.com>
Subject: [OfficeDev/Project-Samples] Can't read if I have more than 20 projects (#6)
When I try to use this on a site with more than 20 projects I get an error trying to 'read' or 'manage' those projects. This is because of a hard limit in CSOM I think? Maybe you can offer a way to filter so regardless of how many I can see some.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FOfficeDev%2FProject-Samples%2Fissues%2F6&data=02%7C01%7Cv-ribix%40microsoft.com%7C0e55261f11d34dec0e3f08d42526f6bf%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636174296654654834&sdata=tX5X%2FxXFI7LXQd7PHJ5K69qJuFN21d%2Bh2KZ32L6pif0%3D&reserved=0>, or mute the thread<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARl5_PmvckAkliJdFy8ZPSVIZkGIIzrzks5rIZ-cgaJpZM4LOhZB&data=02%7C01%7Cv-ribix%40microsoft.com%7C0e55261f11d34dec0e3f08d42526f6bf%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636174296654654834&sdata=F0pUJHkcC5b2pIZ7%2B%2BQ%2BX%2BWiESoTyM3dIOugQlrQIw0%3D&reserved=0>.
JBoman32768 commented