How to get users from SharePoint Group
in Visual Studio 2013 workflows



Posted on September 25th, 2014

In this post, you will learn how to get users from SharePoint group in Visual Studio 2013 workflows.

We are sharing on workflows in SharePoint 2013 and Office 365 using Visual Studio 2013. These apply to both on-premises and online. All these blog posts based on SharePoint hosted apps.

Let us check what workflow activities are required getting all users from SharePoint group.

Workflow Activities:

In this workflow, we will use below workflow activities to get users from SharePoint group in workflows using Visual Studio 2013.

  • LookupSPListItem
  • GetDynamicValueProperties
  • Assign
  • WriteToHistory
  • HttpSend
  • GetDynamicValueProperty<T>

We have explained more details about above activities in previous posts.

  • BuildCollection<T>
  • AddToCollection<T>

To learn more about Building workflows, click the image below and enroll in the FREE course.

Workflow:

The below images shows various workflow activities that have been used for getting users from SharePoint group and adding group member email to a collection.

Please check our previous blog post,  steps 1, and 2 on how to create a list workflow. We are also reusing the workflow configuration to get app web URL and SharePoint group exists from our previous blog posts. This post is a continuation of previous posts in this series.

You can see in the below images, Fig1: represents to make "Rest call for getting user information from the Product Owners group"(Steps 1, 2, 3 and 4).

Fig 2: Shows "Getting Users Email address and storing in a collection object"(steps 5, 6, 7, 8 and 9).

Rest call for getting user information from Product Owners group

Fig1: Rest call for getting user information from Product Owners group.

Step1:

We are building the Rest query to get all users from SharePoint group i.e. Product Owners.

We are reusing Rest uri build for SharePoint Group and appending Users to that.

SharePoint group:

RestApi = string.Format("{0}_api/web/sitegroups/getbyname('" + GroupName + "')", Appweburl);

Getting Users from SharePoint group:

RestApi = RestApi +"/Users";

Step2:

In step 2, we are making Rest call using HttpSend activity to get the users data in JSON format.

Rest call for getting user information from Product Owners group

Step3:

In Step 3, we are using the response from HttSend activity and get the results data into a dynamicvalue.

Storing Users data into ProductOwnersgroupUsersData DynamicValue

Step 4:

In step 4, we are initializing the collection object to store all users emails so that we can use this object to send emails to all users.

Building collection to store User Emails
Getting Users Email address and storing in a collection object

Fig 2: Getting Users Email address and storing in a collection object.

Step 5:

In this step, we are using for-each activity to loop through all user data which is stored in ProductOwnersgroupUsersData DynamicValue variable from GetDynamicValueProperties activity.

For-each activity to loop through all user data

Step6:

Step 6 is a sequence which consists of Steps 7, 8 and 9.

Step7:

In Step 7, we are using GetDynamicValueProperty<System.string> activity to capture Email property of each Item.

Capture Email property of each Item

Step8:

In this step, we are adding each user email to the collection defined in Step 4.

Adding each user email to the collection

Step9:

In this step we are logging Users email data to workflow history.

To learn more about Building workflows, click the image below and enroll in the FREE course.

Workflow Variables:

Below is the list of variables we have used within the workflow.

Workflow Variables

Once you are done with workflow, lets start testing it.

Testing:

Right-click on the project and click on deploy. Once we deploy it, add an item in the Products list, and it should start the workflow automatically. Now go to workflow status page to check the workflow history Info, it will display all the "Product Owners" SharePoint group users emails.Please see below screenshot for reference.

Workflow History

Code Repository:

You can download the source code by clicking on images below.

Conclusion:

In this post, you have learned how to get users from SharePoint group in Visual Studio 2013 workflows.

To learn more about Building workflows, click the image below and enroll in the FREE course.

› How to get users from sharepoint group in visual studio 2013 workflows



Join 6,500 subscribers and receive instant access to

Devendra's Library of Resources for SharePoint Developers

About Author

Devendra Velegandla is a four-time recipient of Microsoft's Most Valuable Professional (MVP) award (2014-2017) for Office Servers and Services MVP and  SharePoint Server. He received the MCC award for his contributions in Microsoft MSDN/TechNet forums. He loves sharing articles, videos, and tutorial on SharePoint and Office 365.