How to get termstore GUID by giving its name.

sumacasu 11 Reputation points
2021-03-03T16:14:42.027+00:00

Hello :-)

I'm looking for help; I'm trying to find out how to get the termset ID using javascript/Angularjs.

Right now, my code is as follows; I don't want to have hardcoded the TermSet Ids.. do you know a way to get the ids?

I really appreciate any help you can provide.

My code below:

var termStore = taxonomySession.getDefaultSiteCollectionTermStore();
var SiteEnvironment = location.hostname;

if (SiteEnvironment == 'URL.sharepoint.com') {
var termSet;
if (termSetName == "ABC"){
termSet = termStore.getTermSet('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX');
}
else if (termSetName == "DEF")
termSet = termStore.getTermSet('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX');
else if (termSetName == "GHI")
termSet = termStore.getTermSet('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX');
} else {
if (SiteEnvironment == 'URL.sharepoint.com') {
var termSet;
if (termSetName == "ABC"){
termSet = termStore.getTermSet('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX');
}
else if (termSetName == "DEF"){
termSet = termStore.getTermSet('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX');
}
else if (termSetName == "GHI"){
termSet = termStore.getTermSet('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX');
}
}
}

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,210 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-03-04T05:31:16.14+00:00

    My test code for your reference:74113-code.txt
    Test result:
    74123-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.