Skip to content

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

@stuartpaulin

Description

@stuartpaulin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions