0

Goal: I have a Person column on a SharePoint list called Manager and I'd like to return the Manager Email for each list item as well as the value of a managed metadata field. I'm using the PnP JS library, but unfortunately the metadata Label field of a managed metadata field return the id in a string as the label and not the value of the term.

I've now tried to do a CAML query, which resolves the managed metadata issue but now I'm not sure how to grab the EMail property of the Person field.

Here's what I have so far:

const caml: ICamlQuery = {
            ViewXml:
                "<View><ViewFields><FieldRef Name='Manager'/><FieldRef Name='BusinessUnit' /></ViewFields><RowLimit>5</RowLimit></View>",
        };
        const r = await this._sp.web.lists.getById(`${listId}`).getItemsByCAMLQuery(caml);
        console.log({ r });

Right now I'm only getting the ManagerId and ManagerStringId returned.

1 Answer 1

1

There is a way to the get the Term label on Rest API without CAML too. You have to request the field "TaxCatchAll".

You can request the field by doing this on the request:

.select("TaxCatchAll/ID","TaxCatchAll/Term")
.expand("TaxCatchAll")

The value of that field is an array with all the ids and matching labels for your current item. With this, you will be able to map those ids you mentioned to the matching label.

You need permissions on the hiddentaxonomylist of the SiteCollection to be able to get this field.

For the EMail property of the manager. You can request those on the query with:

.select("Author/EMail")
.expand("Author")
1
  • I'll have to try that out -- really appreciate it. I was able to get CamlQuery to work by doing the following: const caml: ICamlQuery = { ViewXml: <View><ViewFields>${fieldRefs}</ViewFields><RowLimit>12</RowLimit></View>, }; const r: IRenderListDataAsStreamResult = await this._sp.web.lists .getById(${listId}) .renderListDataAsStream(caml); const items = r.Row;
    – Jono Suave
    Mar 15, 2023 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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