Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get list page by page (by parts) #142

Open
agamaya-user opened this issue Nov 4, 2017 · 1 comment
Open

How to get list page by page (by parts) #142

agamaya-user opened this issue Nov 4, 2017 · 1 comment

Comments

@agamaya-user
Copy link

I have a long list and when I try to read it, I get an exception:
Error (Receiver) Operation timed out after 10000 milliseconds with 0 bytes received,more='

so I need to read this list by parts, first 1000 items, then second 1000 items and so on.
How can I do this ?

@mgroat
Copy link
Contributor

mgroat commented Aug 6, 2019

There's no built-in way to do it, but here's a workaround that I've used:

function getSharePointAll($sp, $listName) {
	$pageSize = 1000;
	$currentMax = -1;
	$totalResult = [];
	while(true) {
		$currentResult = $sp->query($listName)->where("ID",">",$currentMax)
				->limit($pageSize)->sort('ID','ASC')->get();
		
		//We get a 'No data returned.' warning after we've collected everything
		if(isset($currentResult['warning'])) {
			break;
		}
		$currentMax = end($currentResult)['id'];
		$totalResult = array_merge($totalResult,$currentResult);
	}
	return $totalResult;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants