Showing posts with label pnp recursive. Show all posts
Showing posts with label pnp recursive. Show all posts

Wednesday, 18 December 2019

Get SharePoint LisItem using pnp recursively




private async GetAllItemsRecursivly()
{
      // the query also works with select to choose certain fields and top 
//to set the page size
    let items = await pnp.sp.web.lists.getByTitle("Navigation").items.
filter("Title eq 'Department'").select("Title,Id").top(5).getPaged();
    // the results property will be an array of the items returned
    console.log("We got results!");
    for (let i = 0i < items.results.lengthi++)
    {
        // type checking works here if we specify the return type
        console.log(items.results[i].Id);
    }

    // the hasNext property is used with the getNext method to handle paging
    // hasNext will be true so long as there are additional results
    while(items.hasNext)
    {
        // this will carry over the type specified in the original query 
//for the results array
        items = await items.getNext();
        for (let i = 0i < items.results.lengthi++)
        {
          // type checking works here if we specify the return type
          console.log(items.results[i].Id);
        }
    }
}