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

ListItemCollectionPosition in CamlQuery #305

Open
kevinlaucw opened this issue Nov 4, 2022 · 0 comments
Open

ListItemCollectionPosition in CamlQuery #305

kevinlaucw opened this issue Nov 4, 2022 · 0 comments

Comments

@kevinlaucw
Copy link

kevinlaucw commented Nov 4, 2022

Hi,

I'm trying to work with the offset in paging with CamlQuery but $qry->ListItemCollectionPosition doesn't seem to work. I tested the same code logic in C# and it worked.

PHP 8.1.10

My Code


$view_xml ="<View><Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query><RowLimit>10</RowLimit></View>";

$list = $client->getWeb()->getLists()->getByTitle($list_title);

$qry = new CamlQuery();
$qry->ViewXml = $view_xml;

$items = $list->getItems($qry);
$client->load($items);
$client->executeQuery();
	
$start_position = new ListItemCollectionPosition();
$start_position->PagingInfo = "Paged=TRUE&p_ID=20";

//echo $items->ListItemCollectionPosition()."<br>"; // this doesn't work in PHP but works fine in C#. Missing ListItemCollection in ListItemCollection.php?

$qry->ListItemCollectionPosition = $start_position; // this line errors out when executing query but works fine in C#
$items = $list->getItems($qry);
$client->load($items);
$client->executeQuery();

Error


Fatal error: Uncaught Office365\Runtime\Http\RequestException: 
{
	"error":
	{
		"code":"-1, Microsoft.Data.OData.ODataException",
		"message":
		{
			"lang":"en-US",
			"value":"The property 'query' does not exist on type 'SP.ListItemCollectionPosition'. Make sure to only use property names that are defined by the type."
		}
	}
} in C:\xampp\htdocs\CRM\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php:216 
Stack trace: 
	#0 C:\xampp\htdocs\CRM\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php(172): Office365\Runtime\ClientRequest->validate(Object(Office365\Runtime\Http\Response)) 
	#1 C:\xampp\htdocs\CRM\vendor\vgrem\php-spo\src\Runtime\OData\ODataRequest.php(142): Office365\Runtime\ClientRequest->executeQueryDirect(Object(Office365\Runtime\Http\RequestOptions)) 
	#2 C:\xampp\htdocs\CRM\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php(149): Office365\Runtime\OData\ODataRequest->executeQueryDirect(Object(Office365\Runtime\Http\RequestOptions)) 
	#3 C:\xampp\htdocs\CRM\vendor\vgrem\php-spo\src\Runtime\ClientRuntimeContext.php(96): Office365\Runtime\ClientRequest->executeQuery() 
	#4 C:\xampp\htdocs\CRM\aa.php(96): Office365\Runtime\ClientRuntimeContext->executeQuery() 
	#5 {main} 
thrown in C:\xampp\htdocs\CRM\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php on line 216

C# code that works

CamlQuery query = new CamlQuery();
query.ViewXml =
    "<View>" +
    "   <Query>" +
    "      <Where></Where>" +
    "   </Query>" +
    "   <OrderBy>" +
    "       <FieldRef Name='ID' Ascending='True' />" +
    "   </OrderBy>" +
    "   <RowLimit>10</RowLimit>" +
    "</View>";

collListItem = targetList.GetItems(query);
context.Load(collListItem);
context.ExecuteQuery();

string msg = "Results:\n";

var position = collListItem.ListItemCollectionPosition;
ListItemCollectionPosition startPosition = new ListItemCollectionPosition();
startPosition.PagingInfo = "Paged=TRUE&p_ID=10";
query.ListItemCollectionPosition = startPosition;       // this line works in C# but not phpSPO.
collListItem = targetList.GetItems(query);
context.Load(collListItem);
context.ExecuteQuery();

foreach (ListItem myListItem in collListItem)
    msg += "\nID=" + myListItem["ID"];
Console.WriteLine(msg);
listBox1.Items.Add(msg);

Any helps would be much appreciated.

Thank you.

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

No branches or pull requests

2 participants