Nintex Workflow: Checking if a user is a member of a SharePoint group

I posted this a while back on an older blog which is no longer up, this was originally written up for SharePoint 2010 but it does also work on SharePoint 2013. I thought I’d re-post it and update the screenshots as I feel it’s a good reference, even just for myself.

 

I was asked by a client if it was possible to setup a workflow that behaves differently for users in an Approvers group versus regular site users. While this is possible there isn’t a built in action in Nintex to do this. It was instead necessary to query the SharePoint UserGroup.asmx web service to get this information.

In this example I will be configuring a workflow on a document library and will be using the ‘Modified By’ field to get the user who triggered the workflow.

To start with I configured the following variables.

 

Variable Name Type Description
GroupExists Yes/No Set if user resides in the SharePoint group being checked
User Single Line of Text Stores the account name of the user that will be checked
UserGroupXML Multiple Lines of Text Used to store the results from the web service (XML)
UserGroupNames Collection Web service results are parsed and the resulting SharePoint groups are stored

 

1. Set the ‘User’ variable

The first action sets the ‘User’ variable to the account name defined in the ‘Modified By’ field. Ensure that the return type is set to Login Name, this will be used later on as the parameter for the UserGroup.asmx web service.

Workflow Action: Set variable
Set: ‘User’ equal to List Lookup – Current Item – Modified By (Login Name)

2. Query the SharePoint web service

We then query the UserGroup.asmx web service using the method ‘GetGroupCollectionFromUser’. This returns XML containing the SharePoint groups that the user is a member of.

Configure the call to the web service as shown below. Obviously replace the URL and credentials with the correct values for your environment.

3. Retrieve group names where the user is a member

Next we strip out the majority of the XML returned by the web service and get just the group names. The XML is processed using the following XPath and the results are stored in the UserGroupNames variable.

/defaultNS:GetGroupCollectionFromUser/defaultNS:Groups/defaultNS:Group/@Name

The resulting configuration should be similar to that shown below.

4. Check if a particular group exists

Since we have stored the group names in a collection variable it is now very easy to find out if a value exists in the collection. For this we will use the ‘Collection operation’ action.

For my example I used the following configuration.

5. ??? – Profit!

The ‘GroupExists’ variable is now either true or false indicating whether the person who modified the document is in the “Approvers” group. This gives us the option to do a range of things such as branching off and performing an entirely different set of actions due to this outcome.

Since this is a bit of work to set up initially it is well suited for a Nintex User Defined Action. Many users can then implement this functionality in their workflows without needing to know the technical details such as the web service URL.

Leave a Reply

9 Comments

  1. Patrick

    Hi Tom,

    Happy New Year!

    Thanks for your blog I am going to try this in my new workflow.

    I very new with Nintex and I have two question may you can help me.

    1. How can I set a counter in Nintex workflow for an e-mail notification, I want to send only twice an e-mail for approval.

    2. I have a list where I get an automatic generated id for a new task with Nintex workflow
    How can I delet memory of this Ids – of workflow generator because I want delete some previous ids from the list and I want to start again with generating new id numbers.

    Thanks
    Patrick

    • Tom O'Connor

      Hi Patrick,

      Thanks, same to you!

      1. I’m assuming the workflow is running once for each approval? If so, you would need to store the counter outside of the workflow probably against the list/document itself. The workflow could then read this field and if it is equal to ‘2’ it doesn’t send an email otherwise it increments the field and sends the notification.

      2. Unfortunately you can’t, a task list is like any other SharePoint list. ID’s are recorded incrementally and once an ID has been used there is no way to reuse the ID for another item. The only thing you can do is delete and recreate the task list.

      Let me know how you go with following my post. If you run into any problems or there is something that isn’t clear feel free to let me know.

      Cheers,

      Tom

  2. Hi Tom,

    Great post! I’m actually looking for something similar to what you posted but with a twist. I’m checking to see if a user belongs in a group or many groups. if true then email that user. The problem for me is that if a user belongs in many groups they receive multiple emails. I only want them to get one email. Interested on your ideas on doing this in Nintex.

    Thanks,

    b

    • Tom O'Connor

      When you query the XML this should be returning all groups that this user is a member of. That way you could just add multiple collection operations (Step 4) to check if the user exists in a particular group and save each result to its own variable.

      Then just add a condition that checks each variable before sending an email, if any variables are true the email gets sent.

      • Hi Tom,

        Thanks for the response. your method was very helpful. For me, writing the xpath seems to be a challenge. In addition, my other challenge is querying a multiselect column (check boxes) where a user can belong to many of them boxes checked. Each check box represents a security group in which they belong for item level permissions. Is there a good way to query this?

      • Tom,
        Have you had any experience attaching dynamic number of attachments to send in an email?

  3. Thank you for this. I was trying to get an action to run if the user was the member of a specific group and this method worked.

Next ArticleHow to use jQuery to track Google Analytics events on SharePoint