phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

ListItemCollectionPosition in CamlQuery

Open kevinlaucw opened this issue 4 years ago • 0 comments

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.

kevinlaucw avatar Nov 04 '22 11:11 kevinlaucw