Sharepoint - How to get Termset using the new SharePoint framework SPFx

There is a sample for Taxonomy in sp-dev-fx-webparts. Following things you can get from this sample

  • Reading taxonomy term stores' hierarchy from SharePoint
  • Loading JavaScript Object Model scripts
  • creating Knockout components

I believe you can get help from this file to get term Termset.


You can use @pnp/sp-taxonomy/terms.

Install with:

npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp @pnp/sp-taxonomy @pnp/sp-clientsvc -- save

Import:

import { Session } from '@pnp/sp-taxonomy';

Usage:

const taxonomy = new Session(siteCollectionURL);
const store: any = taxonomy.termStores.getByName(termStoreName);
store.getTermSetById(termsetId).terms.select('Name', 'Id', 'Parent').get()
.then((data: any[]) => {
  console.log(data)
})

Docs: https://github.com/pnp/pnpjs/blob/dev/packages/sp-taxonomy/docs/terms.md

Tags:

Spfx