I am trying to read a term set (Ideally I want it in tree order) but haven't figured out a simple way of doing that yet. So I have the below working about from the line where I am trying to read the parent ID. I get the following: "Uncaught Error: The property or field 'Id' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."

can anyone point me in the right direction?

    <script type="text/javascript">

    var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";

    $.getScript(scriptbase + "SP.Runtime.js",
        function () {
            $.getScript(scriptbase + "SP.js", function(){

                $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);



    var array_terms=[];

    function execOperation(){

    //Current Context
    var context = SP.ClientContext.get_current();

    //Current Taxonomy Session
    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);

    //Term Stores
    var termStores = taxSession.get_termStores();

    //Name of the Term Store from which to get the Terms.
    //var termStore = termStores.getByName("Psoriasis");
    var termStore = termStores.getById("1d2d0ed9255a44838b19a8ca1f538ad7")

    //GUID of Term Set from which to get the Terms.
    var termSet = termStore.getTermSet("a7dcd694-49d7-4e07-a405-3dc31d53ddb3");

    var terms = termSet.getAllTerms();



    var termEnumerator = terms.getEnumerator();

    var termList = "<table><tr><th>Name</th><th>ID</th><th>Custom sort</th><th>Terms Count</th><th>Term Path</th><th>Term Parent</th></tr>";


            var currentTerm = termEnumerator.get_current();

            var term_name = currentTerm.get_name();
            var term_id = currentTerm.get_id();
            var term_customsortoder = currentTerm.get_customSortOrder();
            var term_parent = currentTerm.get_parent();
            var terms_count = currentTerm.get_termsCount();
            var term_path = currentTerm.getPath();
            var term_allterms = currentTerm.getTerms();

            var parent_id = term_parent.get_id();           

            termList += "<tr><td>"+term_name+"</td><td>"+term_id+"</td><td>"+term_customsortoder+"</td><td>"+terms_count+"</td><td>"+term_path+"</td><td>"+term_parent+"</td></tr>";

        termList +="</table>"






I have been looking for the answer to this one too. The following should retrieve the extra properties:

//paste code on one line

context.load(tsTerms, 'Include(IsRoot, Labels, TermsCount, CustomSortOrder, Id, IsAvailableForTagging, Name, PathOfTerm, Parent, TermSet.Name)');

The following blog had some good examples that have helped me get my code working.

Recursive parent to child termset code: https://cann0nf0dder.wordpress.com/2013/04/09/accessing-taxonomy-term-store-with-jsom/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.