Skip to content

Instantly share code, notes, and snippets.

@codegard1
Last active December 27, 2018 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegard1/a5023ec6c5f6405a9c3e5e5f9db7549e to your computer and use it in GitHub Desktop.
Save codegard1/a5023ec6c5f6405a9c3e5e5f9db7549e to your computer and use it in GitHub Desktop.
<div id="results"></div>
<script type="text/javascript">
console.time('initialize');
function retrieveWebSiteProperties(siteUrl) {
var clientContext = SP.ClientContext.get_current();
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("Site") !== -1) {
console.log( oList.get_title() );
listInfo.push(
// Create a P element and append it to the listInfo array
jQuery('<p/>').text('Title: ' + oList.get_title() + ' Created: ' +
oList.get_created().toString())
);
}
}
jQuery("#results").html(listInfo);
console.timeEnd('initialize');
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
console.timeEnd('initialize');
}
// Define the "starting" method that executes the callback
function initialize() {
SP.SOD.executeFunc("sp.js", "SP.ClientContext", function () {
// This will run after SP.js is loaded.
retrieveWebSiteProperties(_spPageContextInfo.webAbsoluteUrl);
});
}
// Add the initializing method to the load queue
_spBodyOnLoadFunctionNames.push('initialize');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment