Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisobriensp/34e515cb36a77c1f5c18fb4735fe79e4 to your computer and use it in GitHub Desktop.
Save chrisobriensp/34e515cb36a77c1f5c18fb4735fe79e4 to your computer and use it in GitHub Desktop.
TypeScript helper methods related to use of PnP Taxonomy Picker SPFx React control.
// used to get object suitable for writing a single-valued taxonomy value to SharePoint from the PnP taxonomy picker control..
private static getTaxonomyTerm(termDetails: IPickerTerm): ITaxonomyTerm {
let taxonomyTerm: ITaxonomyTerm;
if (termDetails) {
taxonomyTerm = {
TermGuid: termDetails.key,
Label: termDetails.name,
WssId: -1
};
}
return taxonomyTerm;
}
// used to get object suitable for setting current value of PnP taxonomy picker control from data fetched from SharePoint..
private static getPickerTerm(retrievedTaxValue: ITaxonomyTerm, taxCatchAll: Array<any>): IPickerTerm {
let pickerTerm: IPickerTerm;
if (retrievedTaxValue) {
if (taxCatchAll && taxCatchAll.length > 0 && retrievedTaxValue) {
const result = taxCatchAll.filter(item => item.ID === retrievedTaxValue.WssId);
if (result.length === 1) {
pickerTerm = {
name: result[0].Term,
path: result[0].Term,
key: retrievedTaxValue.TermGuid,
termSet: undefined,
termSetName: undefined
};
} else {
console.warn("setTaxonomyTerm: WARNING! Unable to load value for field: " + retrievedTaxValue.Label);
console.warn({ taxCatchAll });
}
}
}
return pickerTerm;
}
@Ofer-Gal
Copy link

How do you get TermGuid from taxCatchAll?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment