How to hide list and library while creating them?
-
10-10-2020 - |
Question
Code which I have tried
list = web.get_lists();
var listCreation = new SP.ListCreationInformation();
listCreation.set_title(ListName); //Passing list Name
if (ListType == "SP.ListTemplateType.PictureLibrary") {
listCreation.set_templateType(SP.ListTemplateType.pictureLibrary);//Passing List Type
}
else {
listCreation.set_templateType(SP.ListTemplateType.genericList);//Passing List Type
}
//to hide list and libraries
list.Hidden = true;
//list.BreakRoleInheritance(false, false); //clear role assignments for a List
list.add(listCreation);
context.load(list);
Solution
Hidden
property does not exist in SP.ListCreationInformation()
but SP.List
has hidden property. So you can hide your list only after creating it.
var clientContext = SP.ClientContext.get_current();
var web = clientContext.get_web();
var list = web.get_lists().getByTitle('List Title');
list.set_hidden(true);
list.update();
clientContext.load(list);
clientContext.executeQueryAsync(
function() {
console.log(list.get_hidden())
},
function() {
console.log("error occured")
});
Update
You can hide a list while creating it using REST API. As you are using SharePoint Online so you can consider it as well.
var data = {
'__metadata': {
'type': 'SP.List'
},
'BaseTemplate': 100,
'Description': 'Test',
'Title': 'test 1',
'Hidden': true
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + '/_api/web/lists',
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify(data),
success: function(data) {
console.log(data);
},
error: function(error) {
alert(JSON.stringify(error));
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange