Created
July 1, 2019 21:33
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you get TermGuid from taxCatchAll?