I'm looping through a number of sites to run a query that checks whether new content has been added to document libraries in that site in the previous three days. However, I'm having problems. When I get to the success callback, it is always on the last doc library, site context in that list. Is there something I'm missing here?
var queryItems = function(myContext, myDocName, mySelector){
function getNewContent(x, y, z) {
var myContext = x,
myDocName = y,
mySelector = z;
function success() {
if( items.get_count() > 0 ) {
$(mySelector).find(".newContent").show();
}
}
function fail() {
console.log("Failed loading new content");
}
var myCtx = new SP.ClientContext(myContext),
myList = myCtx.get_web().get_lists().getByTitle(myDocName),
myQuery = new SP.CamlQuery(),
date = new Date(),
ISODate = ISODateString(new Date( date.getFullYear(), date.getMonth(), date.getDate() - 3 ) );
myQuery.set_viewXml('<View><Query><Where><Gt><FieldRef Name="Created" /><Value Type="DateTime">' + ISODate + '</Value></Gt></Where></Query></View>');
this.items = myList.getItems(myQuery);
myCtx.load( this.items );
myCtx.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, fail));
};
return getNewContent(myContext, myDocName, mySelector);
}
for ( var obj in objDocLibs) {
(function(datum, sel) {
queryItems(context, datum, sel);
})(objDocLibs[obj].name, selector)
}
}