How to add a welcome page based on logged in User in SharePoint 2010/2013/ online?

Hello Sharepointers,

In SharePoint , if we need to place new welcome page based on the logged in user group, below is the CSOM script to achieve the functionality. Place the below code in script editor web part or content editor web part.

function AutoRedirectwelcomepage() {
var clientContext = new SP.ClientContext.get_current();
var currentUser = clientContext.get_web().get_currentUser();
clientContext.load(currentUser);

var userGroups = currentUser.get_groups();
clientContext.load(userGroups);
clientContext.executeQueryAsync(function(){
var groupsEnumerator = userGroups.getEnumerator();
while (groupsEnumerator.moveNext()) {
var group= groupsEnumerator.get_current();
if(group.get_title() == “VisitorGroup”) {
window.location.href = _spPageContextInfo.webAbsoluteUrl + “/Pages/welcomePage1.aspx”
break;
}

}

}, function(err){
alert(err);
});
}

SP.SOD.executeOrDelayUntilScriptLoaded(AutoRedirectwelcomepage,’sp.js’);

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published.