phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Retrieving a large list of items from sharepoint - new method confusion

Open stuartpaulin opened this issue 1 year ago • 1 comments

Referring to the 3.0.1 change that meant the old getItems() now only returns 100 items and the replacement is a getAll().

I note from the notes the suggested method is: $ctx = (new ClientContext($siteUrl))->withCredentials($credentials); $list = $ctx->getWeb()->getLists()->getByTitle("--large list title--");

$allItems = $list->getItems()->getAll(5000, function ($returnType){ print("{$returnType->getPageInfo()} items loaded...\n"); })->executeQuery();

In the large items example file similar but different code is suggested.

I replaced my function:

private function getSharePointListByTitle($titleURL)
{
    $list = $this->ctx->getWeb()->getLists()->getByTitle($titleURL);

    $items = $list->getItems();
    $this->ctx->load($items);
    $this->ctx->executeQuery();

    return $items;
}

with

private function getSharePointListByTitle($titleURL)
{
    $list = $this->ctx->getWeb()->getLists()->getByTitle($titleURL);

    $allItems = $list->getItems()->getAll(5000, function ($returnType){
        print("{$returnType->getPageInfo()} items loaded...\n");
    })->executeQuery();

    return $allItems;
}

But no luck. I can see that 567 items are returned in the sub function and printed to screen, but I can't see how I can extract them to actually use them. Would you expand on the example to explain it please. I'm guesing it is something like another $allItems->getYesReallyGetThemNow(); or something???

Meantime I ended up dropping back to 3.0.0 Thanks heaps

stuartpaulin avatar May 22 '23 03:05 stuartpaulin