I know that I am just mising something, but here is the issue:
I have created a helper function:
var RADON = window.RADON || {};
RADON.csom = RADON.csom || {};
RADON.csom.GetLookupData = function () {
var getvalues = function (site, list, field) {
var xml = "<View><Method Name='Read List' /><Query><OrderBy><FieldRef Name='" + field + "'/></OrderBy><Where><IsNotNull><FieldRef Name='" + field + "'/></IsNotNull></Where></Query>";
xml += "<ViewFields>";
xml += "<FieldRef Name='" + field + "'/>";
xml += "<FieldRef Name='ID'/>";
xml += "</ViewFields>";
xml += "</View>";
var deferred = $.Deferred();
var ctx = new SP.ClientContext(site);
this.list = ctx.get_web().get_lists().getByTitle(list);
this.caml = new SP.CamlQuery();
this.caml.set_viewXml(xml);
this.items = this.list.getItems(this.caml);
ctx.load(this.items);
ctx.executeQueryAsync(Function.createDelegate(this, function () { deferred.resolve(this.items); }), Function.createDelegate(this, function (sender, args) { deferred.reject(sender, args); }));
return deferred.promise();
};
return {
getvalues: getvalues
};
} ();
RADON.csom.FillDropdowns = function (items, field, dropdowns, cascade, cascadesite, cascadelist, cascadefield) {
var opts = "<option value='Select...'>Select...</option>";
var enumerator = items.getEnumerator();
var unique = "";
while (enumerator.moveNext()) {
var li = enumerator.get_current();
if (li.get_item(field) != unique) {
opts += "<option value='" + li.get_item("ID") + ";#" + li.get_item(field) + "'>" + li.get_item(field) + "</option>";
unique = li.get_item(field);
}
}
logit("Dropdowns Length: " + dropdowns.length);
for (var z=0; z <= dropdowns.length; z++) {
$("#" + dropdowns[z]).html("").append(opts);
}
};
This code is called by another function after SP.js is loaded:
function GetLookupValues() {
waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Loading Data...', 'Please wait while the Contract is Loaded...', 76, 400);
RADON.csom.GetLookupData.getvalues(siteurl, "ddl514", "BaseOptionYr").then(
function (items) {
RADON.csom.FillDropdowns(items, "BaseOptionYr", ["Period2", "Period3", "Period4", "Period5", "WhatOptionYear"], false, null, null, null)
lcount += 1;
if (lcount == 3) { Loaded(); }
},
function (sender, args) {
logit("LookupValues Failed 1: " + args.get_message());
}
);
RADON.csom.GetLookupData.getvalues(siteurl , "ddl514", "FundsAvailable").then(
function (items) {
RADON.csom.FillDropdowns(items, "FundsAvailable", ["FundsAvailable"], false, null, null, null)
lcount += 1;
if (lcount == 3) { Loaded(); }
},
function (sender, args) {
logit("GetLookupValues Failed 2: " + args.get_message());
}
);
RADON.csom.GetLookupData.getvalues(siteurl, "ddl514", "FundSource").then(
function (items) {
RADON.csom.FillDropdowns(items, "FundSource", ["SourceofFunds"], false, null, null, null)
lcount += 1;
if (lcount == 3) { Loaded(); }
},
function (sender, args) {
logit("GetLookupValues Failed 3: " + args.get_message());
}
);
};
My problem is that the first call runs fine if I rem out the other 2. I am using this to populate dropdowns and there are a lot of different dropdowns I am getting data for. I just feel like the problem could be scope related, but not sure. I get the
"The collection has not been initialized. It has not been requested or the request has not been executed."
error on the other 2 calls