One of the Requirements I am working for, I am getting a list of all the Document libraries present in the SharePoint site using JSOM. Now I have to hide these document libraries from all the users, Just FYI, this is not permissions based. The behavior will be uniform across all users.
I am using below code to get the list of all the libraries.
<script type="text/javascript">
var currentcontext = null;
var currentweb = null;
ExecuteOrDelayUntilScriptLoaded(GetLibrariesOnly, "sp.js");
//to get the list of document libraries.
function GetLibrariesOnly()
{
currentcontext = new SP.ClientContext.get_current();
currentweb = currentcontext.get_web();
this.listCollection = currentweb.get_lists();
listCollection.set_hidden(true);
currentcontext.load(listCollection);
currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
Function.createDelegate(this, this.ExecuteOnFailure));
}
function ExecuteOnSuccess(sender, args) {
var listEnumerator = this.listCollection.getEnumerator();
var allLibs ="";
while (listEnumerator.moveNext())
{
var list = listEnumerator.get_current();
if(list.get_baseTemplate() == '101')
{
allLibs+= list.get_title() + '\n';
}
}
alert("All Libraries:" + '\n' + allLibs);
}
function ExecuteOnFailure(sender, args) {
alert("Error in Getting Libraries");
}
What should I add/change to hide the libraries except the Documents and Site Assets library that appear in the Alert.
I would want to hide all the libraries except site assets and default documents library. Please see below screenshot. I am working with SharePoint online/Office 365. Thanks in advance.