I am using the code below to get all the list of a site. However the user might not have access to all lists, so how can I get only the list the current user has access to?
When accessing the site with an unprivileged user the code below results in
Error: Access denied. You do not have permission to perform this action or access this resource.
Any help here would be much appreciated
var ctx = SP.ClientContext.get_current();
var web = ctx.get_site().get_rootWeb();
function MyFunction(web) {
var ctx = web.get_context();
var webs = web.getSubwebsForCurrentUser(null);
var lists = web.get_lists();
ctx.load(webs, 'Include(Title,Webs,Url)');
ctx.load(lists,'Include(Title,RootFolder,Hidden)');
ctx.executeQueryAsync(
function() { ... },
function(sender,args){
console.log('Error: ' + args.get_message());
}
);
}
MyFunction(web);
Edit: I thought I mention that the code works fine without the get_lists, it shows me the sites the user can access, but I now would like to do the same for the lists on the sites.