Pnpjs: Query items inside a folder

Created on 22 Jan 2019  路  2Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ 1.2.8 ]

Please specify what version(s) of SharePoint you are targeting: [ 2013 ]

Expected / Desired Behavior / Question

I am trying to query recursively all items inside a folder of a SharePoint list. I am adding below the native REST API implementation for what I am trying to achieve:

const viewXml = `<View Scope="RecursiveAll"><Query>${queryText}</Query></View>`;
 const url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems"; 
        console.log(viewXml);
        var queryPayload = {  
                   'query' : {
                          '__metadata': { 'type': 'SP.CamlQuery' }, 
                          'ViewXml' : viewXml,
                          "FolderServerRelativeUrl": folderServerRelativeUrl
                   }
        };
        return $.ajax({
               url: url,
               method: "POST",
               data: JSON.stringify(queryPayload),
               headers: {
                  "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                  "Accept": "application/json; odata=verbose",
                  "content-type": "application/json; odata=verbose"
               }
         });

Is there any method in PnP which supports this operation in SP 2013? I see that renderListDataAsStream supports this, but can it work with 2013?

code answered question

All 2 comments

Yes, the getItemsByCAMLQuery method.

Thanks @patrick-rodgers . Replaced with below pnp code and it works. Life is beautiful :-)
const folderServerRelativeUrl=`${_spPageContextInfo.webServerRelativeUrl}/${listName}/${year}`; const listItems= await pnp.sp.web.lists.getByTitle(listName).getItemsByCAMLQuery({ ViewXml:viewXml, FolderServerRelativeUrl: folderServerRelativeUrl });

Was this page helpful?
0 / 5 - 0 ratings