Hi all,
I need to create a consolidated list of sub sites that span Site Collections. I was wondering if I could set the ClientContext to the entire Web Application and enumerate from there, or selectively state which Site Collections to pull from for the Web enumeration. The code below (pasted into a Script Editor Web Part for testing), works for retrieving all the sub sites within a single Site Collection, but I need to cross over.
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script><script type="text/javascript"> $(function() { // Make sure the SharePoint script file 'sp.js' is loaded before your // code runs. SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady); }); // Create an instance of the current context. function sharePointReady() { var url = "https://yourcompany.com/sites/projects"; var clientContext = new SP.ClientContext(url); if (clientContext != undefined && clientContext != null) { var web = clientContext.get_web(); this.webCollection = web.getSubwebsForCurrentUser(null); clientContext.load(this.webCollection); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed)); } } function onQuerySucceeded() { var webEnumerator = this.webCollection.getEnumerator(); while (webEnumerator.moveNext()) { var web = webEnumerator.get_current(); if(web.get_description() == "Special Site") { $("#SpecialProjects ul").append("<li><a href=" + web.get_url() + ">" + web.get_title() + "</a></li>"); } } } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + args.get_stackTrace()); }</script><div id="SpecialProjects"><h2>Special Projects List</h2><ul></ul></div>
Thanks,
Kelly
Personal Blog: http://thebitsthatbyte.com