1

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);
1

1 Answer 1

2

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));
    }
});
2
  • I was hoping to hide when the list is created. But all the way this works. Thanks
    – user51831
    Jul 27, 2016 at 11:54
  • 1
    You can do that using REST API. Please check my update. Jul 27, 2016 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.