I would like to redirect based on a users group membership. First get the users groups and then have a switch statement to redirect based on 1 of 5 groups.
Below is my code I get to alert that says I get this far then nothing happens in UI
$(document).ready(function () {
// Wait until SP.JS has loaded before calling getWebUserData
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
});
var context = null;
var web = null;
var currentUser = null;
var userGroups = null;
var displayGroups = null;
function getWebUserData() {
context = new SP.ClientContext.get_current(); // Get the current user
web = context.get_web(); // Get the current web
currentUser = web.get_currentUser(); // Get the current user
context.load(currentUser); // Load the current user
userGroups = currentUser.get_groups();
context.load(userGroups);
alert('I get this far then nothing!');
var groupsEnumerator = userGroups.getEnumerator();
alert('var groupsEnumerator ');
while (groupsEnumerator.moveNext()) {
var group = groupsEnumerator.get_current();
displayGroups += group.get_title() + ' \n ';
}
context.executeQueryAsync(onSuccessMethod, onFailureMethod);
}
function onSuccessMethod() {
alert(displayGroups);
alert('User name:' + currentUser.get_title() + '\n Login Name:' + currentUser.get_loginName());
}
function onFailureMethod(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}