Woman In Tech: NAVIGATING THE DIGITAL WORLD

seeker, learner, educator and paying it forward… in short – Jigyaasu

Users and Groups in @Nintex forms for Office 365 – Part 2 (Check if current user belongs to a group)

Posted by

·

,

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;

2016-08-01_11h29_01.png

and whether or not the user belongs to a particular group for your process direction, SPDirectorsGroup in this example.

2016-08-01_12h09_44.png

ALL the groups the logged in user belongs to.

2016-08-01_12h09_13.png

This is one way to retrieve Group and User info using Nintex forms for #Office365.

Users and groups in @Nintex forms for @Office365  – Part 3 (Get the division of current user on form load)

Swetha Sankaran, Microsoft MVP(2017-2020) | Gen AI enthusiast Avatar

About the author

Hi! My name is Joan Smith, I’m a travel blogger from the UK and founder of Hevor. In this blog I share my adventures around the world and give you tips about hotels, restaurants, activities and destinations to visit. You can watch my videos or join my group tours that I organize to selected destinations. [Suggestion: You could use the Author Biography Block here]

Discover more from Woman In Tech: NAVIGATING THE DIGITAL WORLD

Subscribe now to keep reading and get access to the full archive.

Continue reading