This seems to be a common ask, and this is by no means the only way to do this! This is a simple approach using out-of-the-box functionality and can be setup in a few minutes in a site workflow or a list workflow.
Return all users from a SharePoint User Group in First Name Last Name format.
Setup and Overview:
First step is to get the User Group name that we need to interrogate. Once we have that, we can make a web service call and get a collection of all logins, loop through them and build a list of all users. Done.
Here are the variables that I will be using:
**Note that I am doing this as a SITE WORKFLOW and have my varGroupName required and on my start form.
If you want to make this in a list workflow, you will need to alter that piece and feed it in a different way.
1. Get Group Name - This is simple enough, just ask for the user to type it in. Be careful though; it will try to find exactly what you put in, so if it is misspelled, you are not going to get results. We do this in the workflow start form and then feed it into the web service call.
2. Call web service - Here we want to specify the web service (GetUserCollectionFromGroup) and feed it our group name variable. Be sure to test this with an actual group name to ensure you will get results. It will also be helpful when testing and setting up the next step as well. Also, if you want to alter this, it helps to know what XML you are getting back. Then we need to store the resulting XML in a variable and we are set!
3. Query XML - Now that we have our results, we can query the XML and pull out all the users logins. If you grabbed the actual XML from the previous step, you can paste it in the XPath Builder to get the exact XPath you will need. Again, testing with actual data is better so you can see what is going on before you publish and try it. Once setup, simply store the results into our collection variable.
4. Loop for each user in the collection -
Here is where the names get pulled out and first and last names are smashed together.
In our For each action, we want to look at the collUsers and store each one (one at a time) into varUserLogin.
Using Set variable actions, set varUserFirstName and varUserLastName by looking up first name and last name from User Profile details based on varUserLogin, like so:
At this point you have varUserFirstName and varUserLastName and can do whatever you need to with it. Perhaps you need to use it in an email, or write to a list. For this example, I am going to create a full list of all users in the group. I do this by using a Build string action and adding in varUserFirstName and varUserLastName along with the varGroupUsers to continue building on top of itself.
5. Email list of users - Now that I have a full list of users, I can email myself the results:
Again, this is not "the definitive" way to accomplishing this, simply how I did it. I would be interested to know how other accomplished something similar to this, or if someone created a UDA to plug into workflows would be even better. If I have some time, I may do that.
I added the .nwf file here in case anyone wants to grab it and use it. Do note that it is a SITE WORKFLOW, but you can always create the site workflow and then save it as a snippet.
Let me know your thoughts and comments!
Until next time!