How to get Termset using the new SharePoint framework SPFx
-
12-12-2020 - |
Pregunta
I am new to to Typescript, watched videos and created the sample application of client webpart using new SharePoint development framework. All sample application worked well, and using Rest Queries i was able to do some of the List operation.but now my current Project Requirement, to get the termsets values from Taxonomy and as i aware there is no Rest end points available for Termset yet.(let me know if its available.)
I followed https://github.com/gandjustas/sptypescript , for some sample to help for my requirement but with no luck yet.
followed this blog http://thecollaborationcorner.com/2016/08/31/part-4-the-navigation-implementation/#.WD622YVOKM8 . even this is specific to Navigation Termset.
Could anybody help on this, how i can get the Taxonomy termset values using new SharePoint framework.
Solución
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.
Otros consejos
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