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.
|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.
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.