Skip to main content

When designing a Nintex form, it's common that there is a part of the form that should only display to certain users. These sections are usually contained in their own panels within the form. It could be IT administrative details, financial information, or actions for HR to complete. In Nintex On Premises, it is easy to hide this panel based on the current user by using a rule and the inline function fn-IsMemberOfGroup. Unfortunately, that function is not available yet in Nintex Forms for Office 365.
This function is available in O365 Forms, it just does not appear in the Runtime Function list. If you manually type it in, it will work. Here is a list of all supported inline functions.

 

To accomplish this task, I created a hidden text field called "txt_HiddenIsUserAnAdmin" in the form and assigned it the JavaScript variable named jsvar_HiddenIsUserAnAdmin. I then created a rule on the panel that would hide it whenever txt_HiddenIsUserAnAdmin does not equal "Yes". To obtain the groups that the user belongs to without using the inline function, JavaScript must be used. Luckily, the hard work of that development has already been accomplished by Swetha Sankaran in Part 2 of her post on checking if a user belongs to a group. That took me a long way but I had to do a little more to get it to do what I needed.

 

var pollSP;
NWF.FormFiller.Events.RegisterAfterReady(function () {
    pollSP = setInterval(checkSPLoad, 500);
});

function checkSPLoad() {
    if (clientContext) {
        window.clearInterval(pollSP);
        onSPLoad();
    }
}

function onSPLoad() {
    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) {
    try {
        var groupsEnumerator = spGroups.getEnumerator();
        while (groupsEnumerator.moveNext()) {
            var userGroupNames;
            var currentGroup = groupsEnumerator.get_current();
            userGroupNames += currentGroup.get_title() + "
";
            if (currentGroup.get_title() == "Team Site Owners") {
                NWF$("#" + jsval_HiddenIsUserAnAdmin).val("Yes");
                var triggerEventNow = NWF$("#" + jsval_HiddenIsUserAnAdmin);
                triggerEventNow.trigger("blur");
            }
        }
    } catch (err) { alert(err); }
}

function OnFail() {
    alert("Failed to load groups")
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

You'll notice above that I set a hidden text field, jsval_HiddenIsUserAnAdmin, to "Yes". Then I trigger the event which causes the rule on the panel to execute allowing the panel to be seen. Without the trigger, the field will update but the rule will not execute leaving the panel hidden regardless of who is logged in.

 

Another thing to note is that this only works for SharePoint groups, not AD. Unfortunately, that is not supported using JavaScript but you could try querying AD group membership visibility as a workaround.

Hello,

in fact the fn-IsMemberOfGroup is not visible in the editor, but you can use it in a rule

I try it and it works

Check this thread :  

Jean-Marc


Thanks for that. I've updated this post to reflect that and include the inline functions which are also supported according to the documentation.


Reply