I'm currently developing a WebPart for a client using SPFX, React JS and PNP JS where I need to get a full list of Countries from a Countries taxonomy at Tenant level to allow my to populate a dropdown to filter items against, My code is currently returning 18 of the 205 countries and I can't figure out why, for some reason I am getting 2 termSets back to get terms from, both of which return the same 18 terms. Only 1 of the Termstores is actually visible to me.

Here is my code for item retrieval

 export function updateSelections(Set, updateState){
  taxonomy.termStores.getByName(definitions.TermStore).get().then( baseStore => {
    TermStore = baseStore;
    baseStore.getTermSetsByName(Set, definitions.languageCode).get().then( thisTermSets => {
      TermSets[Set] = {};
      thisTermSets.forEach(thisTermSet => {
        thisTermSet.terms.get().then(setTerms => {
          setTerms.forEach(setTerm => {
            const termGUID = setTerm.Id.replace('/Guid(','').replace(')/','');
            setTerm.Id = termGUID;
            TermSets[Set][termGUID] = setTerm;

The values being passed in are the Termset name and a function to store terms in state. TermSets is a global variable that stores values for later internal calls to reduce the number of SharePoint API calls made. The function is generic as I'm using it to retrive various different termsets and only the Countries termset seems to be causing me this issue.

Here is an overview of the code without enclosed functions etc.

  taxonomy.termStores.getByName(TAXONOMYREFERENCEID).get().then( baseStore => {
baseStore.getTermSetsByName('Country', definitions.languageCode).get().then( TermSets => {
  TermSets.forEach(TermSet => {
    TermSet.terms.get().then(Terms => {
      Store terms in memory


Can anyone shed light on where I'm going wrong.

  • Here's a suggestion: don't post your actual solution code, write a very specific sample that illustrates as exactly and succinctly as possible the issue you are facing. Hard code the variables and eliminate the abstractions. Very often when you do this you gain some insight into what's going on, and even if not, answerers will have a much easier time understanding your code. Ideally I could take your example and run it, but with so many unknowns here there's no chance of that. – Derek Gusoff Oct 16 at 15:36
  • 1
    thanks Derek, I will do this just now – Allan MacRitchie Oct 16 at 16:00

Your Answer

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

Browse other questions tagged or ask your own question.