I have queried all of the lists within a subsite but need to filter based on criteria in the title.
I then need to display the filtered list contents. Is this possible if the list contents are not all the same?
Thank you in advance SP community!
This is what I have so far, it is not working:
<script type="text/javascript">
var siteUrl = 'https://myportal/mysite/mysubsite';
// Load the required SharePoint libraries.
$(document).ready(function () {
// The js files are in a URL in the form:
// web_url/_layouts/15/resource_file
var scriptbase = siteUrl + "/_layouts/15/";
// Load the js files and continue to
// the execOperation function.
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js", execOperation);
}
);
});
// Function to execute basic operations.
function execOperation() {
// Continue program flow here.
retrieveWebSiteProperties(siteUrl);
}
function retrieveWebSiteProperties(siteUrl) {
var clientContext = new SP.ClientContext(siteUrl);
this.oWebsite = clientContext.get_web();
this.collList = oWebsite.get_lists();
this.listInfoCollection = clientContext.load(collList);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded(sender, args) {
var listInfo = '';
var listEnumerator = this.collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
if(oList.get_title().indexOf("pro") !== -1){ //if title contains "pro"
listInfo += 'Title: ' + oList.get_title() + ' Created: ' +
oList.get_created().toString() + '\n';
}
}
$("#chartArea").html(listInfo);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
</script>