I am getting this error while using querying a SharePoint list (2010) through JQuery 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.
I am looping through all the options in html select element and querying SharePoint list.
$("#IdeasStatus option").each(function()
{
statusCount = statusCount + 1;
lstStatus.push($(this).val());
});
for (var i = 0; i < lstStatus.length; i++) {
*****Some Code*********
retItems = spList.getItems(caml);
spContext.load(retItems);
spContext.executeQueryAsync(onCategorySuccess, onCategoryFail);}
I am getting error in below function
function onCategorySuccess(sender, args) {
executionCount++;
$('input[id$=hidChartParam1]').val($('input[id$=hidChartParam1]').attr('value') + ',' + status);
$('input[id$=hidChartParam2]').val($('input[id$=hidChartParam2]').attr('value') + ',' + retItems.get_count());
if (executionCount == statusCount) {
FillPieChart();
}
}
error is thrown while fetching the count retItems.get_count() which I believe is because same variable name (retItems) is used while looping and making multiple async calls?
Please suggest what shall I do?
i believe that at some point before calling spList.getItems you should load to the context the spList
Have You call
onCategorySuccess
elsewhere? It looks like you are in theonCategorySuccess
before actually fill inretItems
with values.