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 => {
updateState(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.