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

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)

4 comments

  1. I get an error on executeQueryAsync >>> https://formso365.nintex.com/Pages/FormsPart/_api/contextinfo 404 (Not Found)
    XMLHttpRequest.send @ ai.0.js:1
    executeRequest @ MicrosoftAjax.js:5
    executeRequest @ MicrosoftAjax.js:5
    invoke @ MicrosoftAjax.js:5
    executeQueryAsync @ sp.runtime.js:2
    IsCurrentUser_PlantasVerTodos @ enaex_CommonForms.js:279
    (anonymous) @ enaex_CommonForms.js:194
    EnsureScript @ init.js:1
    EnsureScriptFunc @ init.js:1
    onSPLoadThisNintexForm @ enaex_CommonForms.js:191
    checkSPLoad @ enaex_CommonForms.js:185
    ai.0.js:1 POST https://formso365.nintex.com/Pages/FormsPart/_api/contextinfo 404 (Not Found)

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s