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];
}
}
}
You're loading the list items into a variable named
listItems
, notlist
.Try
var listEnumerator = listItems.getEnumerator();
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
orwindow.onload
and then ensure the load of SharePoint JS libraries by usingSP.SOD.executeFunc
orExecuteOrDelayUntilScriptLoaded
, by example: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?