I have several SP 2010 lists with the exact same columns. I would like to perform a union on the lists and display a filtered subset from this union.
I tried doing it using a joined datasource in SP Designer, but I believe the large amount of data makes this not possible (SP Designer keeps crashing when I try to add a dataview using my joined datasource.)
So, I'm trying to do it with SP.js - it works great for one list, but for some reason I can't seem to make it work for multiple lists. I suspect there is something I don't understand about how the Initialize function works.
Anyway, enough preface, here's the code:
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
getRegionListData("Migrated 2013");
getRegionListData("Migrated 2014");
getRegionListData("Migrated 2011");
getRegionListData("Migrated 2012");
}
function getRegionListData(listName) {
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var list = web.get_lists().getByTitle(listName);
var camlQuery = new SP.CamlQuery();
var q = "<View><Query><Where><Contains><FieldRef Name='aFOS_x0020_Region' /><Value Type='Text'>A2</Value></Contains></Where></Query></View>";
camlQuery.set_viewXml(q);
this.listItems = list.getItems(camlQuery);
clientContext.load(listItems, 'Include(Id, FACID, Description, aFOS_x0020_Region, EncodedAbsUrl)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListItemsLoadSuccess(sender, args) {
var listItemEnumerator = this.listItems.getEnumerator();
var cgRes;
while (listItemEnumerator.moveNext())
{
var item = listItemEnumerator.get_current();
var facid = item.get_item('FACID');
var description = item.get_item('Description');
//var afosReg = item.get_item('aFOS_x0020_Region');
var itemId = item.get_id();
var absUrl = item.get_item('EncodedAbsUrl');
var url = absUrl.slice(0,69);
$('#myTable tr:last').after('<tr><td class=wcContainer><a href=' + url + '/DispForm.aspx?ID=' + itemId + '>View</a></td><td class=wcContainer>' + facid + '</td><td class=wcContainer>' + description + '</td></tr>');
}
var count = this.listItems.get_count();
$('#tdRes').text(count);
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}