Pnpjs: Query List items inside a folder + return expanded values for lookups

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

Category

  • [x] Question

    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 looking for a method which supports below items:

  1. Ability to specify folderurl where the querying must be done
  2. support querying with filter conditions
  3. returns results with expanded values for lookup & managed metadata terms.

So far I tried, getItemsByCAMLQuerywhich supports 1 & 2 but only returns lookup ids not the expanded values.
renderListData does not support item 1.
Am I missing something. What are my options in PnP for this?

sample contribution opportunity馃悋 question

Most helpful comment

In the getItemsByCAMLQuery method, you also have another parameter, expands which basically appends $expand to the query.

Using that, I was able to get lookup and managed metadata terms. I dont have 2013 OnPrem with me, so i tested it in SPO and it gets me the necessary data for lookups and managed metadata fields. It might work on 2013

sp.web.lists.getByTitle("Documents").getItemsByCAMLQuery({
      ViewXml: "<View />",
      FolderServerRelativeUrl:"/sites/testSiteCollection/Documents/TestFolder"
    }, "FieldValuesAsText").then(d => {
      console.log(d.FieldValuesAsText);
    });

All 2 comments

In the getItemsByCAMLQuery method, you also have another parameter, expands which basically appends $expand to the query.

Using that, I was able to get lookup and managed metadata terms. I dont have 2013 OnPrem with me, so i tested it in SPO and it gets me the necessary data for lookups and managed metadata fields. It might work on 2013

sp.web.lists.getByTitle("Documents").getItemsByCAMLQuery({
      ViewXml: "<View />",
      FolderServerRelativeUrl:"/sites/testSiteCollection/Documents/TestFolder"
    }, "FieldValuesAsText").then(d => {
      console.log(d.FieldValuesAsText);
    });

Thanks @gautamdsheth , this works well in SP 2013 too. Additionally, I had to set odata=verbose, as default minimal metadata was not providing FieldValuesAsText properties.

pnp.setup({
            sp: {
                headers: {
                    "Accept": "application/json; odata=verbose"
                }
            }
        });
Was this page helpful?
0 / 5 - 0 ratings