1

Does anyone know why I get

"Uncaught TypeError: list.getEnumerator is not a function"

in my OnSuccess() function?

This code worked fine before, when I tried to get the Titles of all lists in my site collection.

Now I want to get the titles of all rows assigned to John Doe, in my list called testIssues.

What have I missed?

'use strict';
var clientContext = new SP.ClientContext.get_current();
var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var parentContext = new SP.AppContextSite(clientContext, hostweburl);
var parentWeb = parentContext.get_web();
var list = parentWeb.get_lists().getByTitle("testIssues");
var listItems;

$(document).ready(function () {

});

function VisaLista() {
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<View><Query><Where><Geq><FieldRef Name='p32c'/>" +
    "<Value Type='User'>John doe</Value></Geq></Where></Query></View>");
    listItems = list.getItems(camlQuery);
    clientContext.load(listItems);
    clientContext.executeQueryAsync(OnSuccess, OnFail);
}

function OnSuccess() {
    var listString;
    var listEnumerator = list.getEnumerator();
    while (listEnumerator.moveNext()) {
        var currentItem = listEnumerator.get_current();
        listString += "<br/> " + currentItem.get_title();
    }
    $('#divAllaListor').html(listString);
}

function OnFail(sender, args) {
    alert('Failed, Error:' + args.get_message());
}

function getQueryStringParameter(param) {
    var params = document.URL.split("?")[1].split("&");
    var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
        var singleParam = params[i].split("=");
        if (singleParam[0] == param) {
            return singleParam[1];
        }
    }
}
1
  • Make sure your context is initialized after the SP.js library loaded. You should debug your code with the help of developer tools and check, what's coming in the list object (I guess it is coming as a null, that might be the reason.) Commented May 5, 2015 at 9:47

2 Answers 2

3

You're loading the list items into a variable named listItems, not list.

Try var listEnumerator = listItems.getEnumerator();

Sign up to request clarification or add additional context in comments.

Comments

0

Your problem may be related with the time when you execute your code, you must ensure to execute your code at the right moment of the page load process. Try using $(window).load or window.onload and then ensure the load of SharePoint JS libraries by using SP.SOD.executeFunc or ExecuteOrDelayUntilScriptLoaded, by example:

$(window).load(function(){
     SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function (){
          var clientContext = new SP.ClientContext.get_current();
          var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
          var parentContext = new SP.AppContextSite(clientContext, hostweburl);
          var parentWeb = parentContext.get_web();
          var list = parentWeb.get_lists().getByTitle("testIssues");
          var listItems;
          //Call your function here
          VisaLista();
     });
});

Take a look at this thread for more details.

Using jQuery / javascript How to check if JS file ( SP.JS) is already called in a page?

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.