Can anyone help on this.

I am getting the below error.

The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

following is the code.


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

    $.getScript(scriptbase + "SP.Runtime.js", function(){
        $.getScript(scriptbase + "SP.js", function(){
            $.getScript(scriptbase + "SP.Taxonomy.js");
            // SP.SOD.executeOrDelayUntilScriptLoaded('SP.taxonomy.js');
            ExecuteOrDelayUntilScriptLoaded(execOperation, "sp.taxonomy.js");

function execOperation(){

    var context = new 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("Managed Metadata Service");
    //GUID of Term Set from which to get the Terms.
    var termSet = termStore.getTermSet("8a675225-852f-48ed-af73-8fd8e5ccdc14");
    var terms = termSet.getAllTerms();
    termEnumerator = terms.getEnumerator();

        var termEnumerator = terms.getEnumerator();
        var termList = "Terms: \n";
            var currentTerm = termEnumerator.get_current();
            termList += currentTerm.get_name() + "\n";


    }, function(sender,args){

  • please use a debugger and see where the error occurs (which line?) and update your question.
    – helb
    Jun 6, 2018 at 8:05

1 Answer 1


Comment the line

termEnumerator = terms.getEnumerator();

before you are calling the context.executeQueryAsync() getEnumerator will not be initialized before the executeQueryAsync function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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