That is something we do almost every time when building workflows. Indeed, at some point in your process, you need to know who belongs to a SharePoint group and you wonder how to get this user’s list. Of course, there is a SharePoint API for that, but when working with Nintex, the only way, if you don’t want to code your custom action, is to use the SharePoint web services. And because it is something that is regularly needed, it made sense to have a “User Defined Action???, just for that. Not that it is difficult to do, but it is quite useful to have a single action that would return the list of user for a given group.
The SharePoint web service that can be used is located at /_vti_bin/usergroup.asmx . One of the method that can be called and which is especially interesting is GetUserCollectionFromGroup that has the following WSDL signature.
POST /_vti_bin/usergroup.asmx HTTP/1.1
Host: myserver
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: “http://schemas.microsoft.com/sharepoint/soap/directory/GetUserCollectionFromGroup”
<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>
<soap:Body>
<GetUserCollectionFromGroup xmlns=”http://schemas.microsoft.com/sharepoint/soap/directory/”>
<groupName>string</groupName>
</GetUserCollectionFromGroup>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>
<soap:Body>
<GetUserCollectionFromGroupResponse xmlns=”http://schemas.microsoft.com/sharepoint/soap/directory/”>
<GetUserCollectionFromGroupResult>string</GetUserCollectionFromGroupResult>
</GetUserCollectionFromGroupResponse>
</soap:Body>
</soap:Envelope>
As it can be seen, the web method only needs a “groupName??? string parameter and returns a user collection (in other words, an array of users, which is in fact a <Users><User></User></Users> element).
So, to create a useful UDA, the parameters that it should have are :
Parameter | Type | Direction |
The Web Service URL | Text | Input |
The Group Name | Text | Input |
The XML Field you are interested in | Text | Input |
The Collection of Users | Collection | Output |
The special thing here is the “XML Field your are interested in???. Because I didn’t want to limit the UDA to return either the login or the user first or last name, I decided to leave the decision to the user calling the UDA to choose which field to get in the collection. The format of the parameter is directly tied to the XML outputted by the web service :
<GetUserCollectionFromGroup xmlns=”http://schemas.microsoft.com/sharepoint/soap/directory/”>
<Users>
<User ID=”116″
Sid=”S-1-5-21-2110917764-89557993-3811714100-1138″
Name=”domain\annem”
LoginName=”domain\annem”
Email=”anne.m@domain.com”
Notes=””
IsSiteAdmin=”False”
IsDomainGroup=”False”
Flags=”0″ />
</Users>
</GetUserCollectionFromGroup>
If you are interested in the name, the parameter should contain “@Name???, as it is an attribute of the User element. On the other side, if you are interested in the e-mail of the users, then it should contain “@Email???. The image below shows the activities being part of the UDA. Basically, 3 activities are needed : Call Web Service, Query XML, Regular Expression.
To configure the Call Web Service activity, enter the URL of the usergroup site’s web service, for example http://myserver/_vti_bin/usergroup.asmx. Enter the user name and password of an account that has the permissions to call the web service in the appropriate text box. A good practice would be to define a protected constant and to select it using the lock icon. Clicking on the Refresh button will list all the methods available from this web service, so, select the “GetuserCollectionFromGroup??? one:
Once this is done, the parameters will be listed in the “Web service message??? section. You can then replace the different web method arguments by the UDA’s parameters, such as “URL???, “groupName??? and “Store result in???. You will end with the following configuration :
The next activity, “Query XML??? is there to parse the XML response we get from the web method, and to create the collection of users. In the case below, we use the semi-colon as a separator, and we use the “User Field??? UDA’s parameter to match the correct attribute using an XSL, the bold part corresponding to the UDA’s parameter :
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:p=”http://schemas.microsoft.com/sharepoint/soap/directory/”>
<xsl:template match=”p:GetUserCollectionFromGroup/p:Users”>
<xsl:for-each select=”p:User”>
<xsl:value-of select=”{WorkflowVariable:User Field}“/>;</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Finally, the “Query XML??? should look like :
The very last activity is “Regular Expression???. For a reason that I still have to understand, the collection generated by the “Query XML??? activity and stored in the “ParsedGroupUsers??? does not behave like a “correct??? collection. This is why I use such “Regular Expression???, to split the “ParsedGroupUsers??? variable using the semi-colon, and to store the result in the “User Collection??? output parameter :
That’s it !
Publish the User Defined Action and then use this UDA in your workflows.
0 Comments