Taxonomy

The taxonomy class is designed to return the managed metadata term set data as an array of term information, or as a tree.

Getting Term Groups

The getTermGroups() method will return the available term groups from the available term store. The data returned will also include the Site Collection term groups.

Getting a Term Group

The getTermGroup(name:string) method will return a specific term group.

Getting Term Sets

The getTermSets(groupName:string) method will return the available term sets from a specified term group stored in the global term store. The getTermSetsFromDefaultSC() method will return the available term sets from the default site collection’s term group.

Getting a Term Set

By Group Name

The getTermSetByGroupName(name:string, groupName:string) method will return a term set, from a specified term group stored in the global term store.

From Default Site Collection

The getTermSetFromDefaultSC(name:string) method will return a term set from the default site collection’s term group.

By ID

The getTermSetById(termStoreId:string, termSetId:string) method will return a term set.

Getting Terms

By Group Name

The getTermsByGroupName(name:string, groupName:string) method will return an array of terms, from a specified term set located from a specified term group.

From Default Site Collection

The getTermsFromDefaultSC(name:string) method will return an array of terms, from the specified term set located in the default site collection’s term group.

By ID

The getTermsById(termStoreId:string, termSetId:string) method will return an array of terms.

Convert to Tree

The data returned is an array of terms. To convert the terms to a tree object, use the toObject(terms:Array<ITermInfo>). To convert the object back to an array, use the toArray(term:ITerm) method to convert the tree back to an array of terms.

Searching For Data

The findById(term:ITerm, termId:string) method can be used to find a term by its id. The findByName(term:ITerm, name:string) method can be used to find a term by its name. Both methods will require the data to be converted to a tree object first.

Code Examples

// JavaScript
var $REST = require("gd-sprest");

// Get the term groups
$REST.Helper.Taxonomy.getTermGroups().then(function(groups) {
    // Parse the groups
    for(var i=0; i<groups.length; i++) {
        // Code goes here
    }
});

// TypeScript
import { Helper } from "gd-sprest";

// Get the term groups
Helper.Taxonomy.getTermGroups().then(groups => {
    // Parse the groups
    for(let i=0; i<groups.length; i++) {
        // Code goes here
    }
});

Methods

Name Return Type Description
findById(term: ITerm, termId: string) ITerm Searches a term for the specified id.
findByName(term: ITerm, termName: string) ITerm Searches a term for the specified name.
getTermGroups() PromiseLike<Array<ITermGroupInfo>> Gets the term groups from the available term stores.
getTermSets(groupName: string) PromiseLike<Array<ITermSetInfo>> Gets the term sets for a specified term group name.
getTermSetsFromDefaultSC() PromiseLike<Array<ITermSetInfo>> Gets the term sets, from the site collection’s term store.
getTermsById(termStoreId: string, termSetId: string) PromiseLike<Array<ITermInfo>> Gets the terms of a terms set.
getTermSetById(termStoreId: string, termSetId: string) PromiseLike<Array<ITerm>> Gets the terms of a terms set.
getTermsFromDefaultSC(termSetName: string) PromiseLike<Array<ITermInfo>> Gets the terms of a term set, from the site collection’s term store.
getTermSetFromDefaultSC(termSetName: string) PromiseLike<ITerm> Gets the terms of a term set, from the site collection’s term store.
getTermsByGroupName(termSetName: string, groupName: string) PromiseLike<Array<ITermInfo>> Gets the terms of a term set.
getTermSetByGroupName(termSetName: string, groupName: string) PromiseLike<ITerm> Gets the terms of a term set.
toArray(term: ITerm) Array<ITermInfo> Converts a term to an array of term information.
toFieldValue(term: ITerm | ITermInfo) any Converts the term to the field value, formatted for updating an item in the REST API.
toFieldMultiValue(term: Array<ITerm | ITermInfo>) any Converts an array of terms to the multi-field value, formatted for updating an item in the REST API.
toObject(Array<ITermInfo>) ITerm Converts an array of term information to a term.

ITerm

Property Type Description
info ITermInfo The term information.
parent ITerm The parent term.

ITermGroupInfo

Property Type Description
description string The term description
id string The term id
name string The term name

ITermInfo

Property Type Description
description string The term description
id string The term id
name string The term name
parent ITerm The parent term
path Array<string> The term path
pathAsString string The term path as a string
props { [key: string]: string; } The term custom properties

ITermSetInfo

Property Type Description
description string The term description
id string The term id
name string The term name
props { [key: string]: string; } The term custom properties