Get SharePoint groups name(s), the current logged in user belongs to. This can be used to set form fields as well as workflow variables to direct flow of the request process depending on the group current user belongs to.
Task:
To check if logged in user belongs to a particular group
Forms Tool:
Nintex forms for Office 365
Ensuring your SP is loaded prior to getting the current user and groups information as explained in Part 1 of this series.
var pollSP;
NWF.FormFiller.Events.RegisterAfterReady(function(){
pollSP=setInterval(checkSPLoad,500);
});
function checkSPLoad(){
if(clientContext){
window.clearInterval(pollSP);
onSPLoad();
}
}function onSPLoad() {
var currentUser = clientContext.get_web().get_currentUser();
clientContext.load(currentUser);
var spGroups = clientContext.get_web().get_currentUser().get_groups();
clientContext.load(spGroups);
clientContext.executeQueryAsync(
Function.createDelegate(this, function () { OnSuccess(spGroups);}),
Function.createDelegate(this, this.failed)
); }function OnSuccess(spGroups) {
alert(“Groups loaded”);
try {
var isMember = false;
var groupsEnumerator = spGroups.getEnumerator();while (groupsEnumerator.moveNext()) {
var userGroupNames;
var currentGroup = groupsEnumerator.get_current();
userGroupNames += currentGroup.get_title() +”\n”;
if (currentGroup.get_title() == “SPDirectorsGroup”) {
alert(“User is a member of SharePoint Group:” + currentGroup.get_title());
isMember = true;
}
}
alert(“User belongs to these SharePoint Groups:\n”+userGroupNames);
} catch (err) { alert(err);}}
function OnFail() {
alert(“Failed to load groups”)
}
And you are set. Preview the form and you will see that SP Groups are loaded for currentUser;
and whether or not the user belongs to a particular group for your process direction, SPDirectorsGroup in this example.
ALL the groups the logged in user belongs to.
This is one way to retrieve Group and User info using Nintex forms for #Office365.