locked
Retrieving hierarchy of terms from Managed Metadata RRS feed

  • Question

  • I am using the termSet.getAllTerms() method from SP.Taxonomy.js. I am able to get all terms but I don't know which one is child for which one. I need to render the hierarchy of terms in a aspx page in a SharePoint hosed app. I know there is a parent property but it doesn't say so much. How do I get the hierarchy of all terms without calling ExecuteAsync twice.

    thanks

    Thursday, March 13, 2014 1:13 PM

All replies

  • I haven't tried this but see if this helps you

    http://cann0nf0dder.wordpress.com/2013/04/09/accessing-taxonomy-term-store-with-jsom/

    What you do is that in the success method, the way it is in the example above try to iterate through the terms collection obtained and for each term try to find its parent using

    currentTerm.get_parent()




    Geetanjali Arora | My blogs |

    Thursday, March 13, 2014 1:53 PM
  • Thanks, Yes you can get parent but when you try to get its properties it says "it is not been initialized". to get the parent's property you need to call ExecuteAsync more than one time.
    Thursday, March 13, 2014 2:06 PM
  • The below code gets the parents properties
    
    var context = new SP.ClientContext(_spPageContextInfo.siteServerRelativeUrl);
                var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
                var termStore = session.getDefaultSiteCollectionTermStore();
                var termSet = termStore.getTermSet(termSetId);
                var termSetGroup = termSet.get_group();
                var tsTerms = termSet.getAllTerms();
    
                context.load(session);
                context.load(termStore);
                context.load(termSet);
                context.load(termSetGroup);
                context.load(tsTerms, 'Include(IsRoot, Labels, TermsCount, CustomSortOrder, Id, IsAvailableForTagging, Name, PathOfTerm, Parent, TermSet.Name)');

    Saturday, July 5, 2014 2:52 PM