Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save chrisobriensp/34e515cb36a77c1f5c18fb4735fe79e4 to your computer and use it in GitHub Desktop.

Select an option

Save chrisobriensp/34e515cb36a77c1f5c18fb4735fe79e4 to your computer and use it in GitHub Desktop.

Revisions

  1. chrisobriensp created this gist Jul 1, 2019.
    39 changes: 39 additions & 0 deletions PnPJS_TaxonomyPickerHelperMethods.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    // 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;
    }