I would like to find a way how to redirect each user to first accessible subsite in SharePoint 2013.
I have an example of sites' structure:
- MAIN SITE (homepage with links to sites)
- Site1
-Subsite1 -Subsite2 -Subsite3 -Subsite4 - Site2
-Subsite5 -Subsite6 -Subsite7 - Site3
-Subsite8 -Subsite9 -Subsite10 -Subsite11 -Subsite12
- Site1
I need to automatically redirect SP user from Site1 to Subsite1 or (if user has no permissions to subsite1) Subsite2 (or) Subsite3 (or) Subsite4.
This solution should be implemented on each site (1,2,3).
Can somebody help me?
EDIT:
I have now a trouble with executing code (function runCode()):
var webCollection = null;
function runCode() {
var clientContext = new SP.ClientContext.get_current();
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 webName = "";
var webEnumerator = this.webCollection.getEnumerator();
webEnumerator.moveNext();
var web = webEnumerator.get_current();
webName += web.get_title();
window.location.href = "http://sharepoint/sites/m1/s/" + webName;
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}