1

I am using @pnp/sp to get list item data from sharepoint and i am getting list items with managed metadata field and user field. i can get all but not the metadata label which is the one i mainly need. this is my code.

return sp.web.lists.getByTitle(masterListName).items.select("Division", "splistname","Id",  "Editors/Title", "Editors/Id", "Editors/EMail")
        .expand("Editors/Id")
        .filter("Editors/Id eq " + currentUser.Id).get().then((userDivision) => {
            console.log(userDivision);
            return userDivision;
        })

but this is what i get in return .

enter image description here

so instead of the label which is supposed to be "Admin" in this case, i get the ID. i have tried the code that koltyakov has written in https://github.com/pnp/pnpjs/issues/139 but when i tried it, i got an error saying TaxonomyHiddenList does not exist. and i am also not sure how to filter using his syntax.

2

You can use the new RenderListDataAsStream endpoint to get the label values.

PnP JS supports this endpoint which can used. Please modify from below sample code:

 sp.web.lists.getByTitle(masterListName).renderListDataAsStream({
    RenderOptions: RenderListDataOptions.ListData,
    ViewXml :  `<View>
                    <ViewFields>
                        <FieldRef Name="Division"/>
                        <FieldRef Name="splistname"/>
                        <FieldRef Name="Id"/>
                        <FieldRef Name="Editors"/>
                    </ViewFields>      
                    <Query>
                        <Where>
                          <Eq>
                              <FieldRef Name="Editors" LookupId="TRUE" />
                              <Value Type="Lookup">${currentUser.Id}</Value>
                          </Eq>
                        </Where>
                    </Query>
                </View>`
}).then((userDivision) => {
    console.log(userDivision);
});

Also, ensure that you are importing it correctly as:

import { sp, RenderListDataParameters } from "@pnp/sp";

Reference - Using the SharePoint RenderListDataAsStream API to fetch lookup and single managed metadata field values

Getting term label values with the SharePoint RenderListDataAsStream API endpoint

Working with list items in REST API

  • thank you! but i am not sure if i am implementing this right because param is returning undefined. "Cannot set property 'RenderOptions' of undefined" i have imported RenderListDataParameters correctly – Page F.P.T Sep 19 '18 at 6:54
  • my bad, please check edited code – Gautam Sheth Sep 19 '18 at 7:20
  • yes thank thank you! i should read the docs more i apologize THANK YOU! – Page F.P.T Sep 19 '18 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.