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.
In this workflow, we will use below workflow activities to get users from SharePoint group in workflows using Visual Studio 2013.
We have explained more details about above activities in previous posts.
Click links below to learn more about Visual Studio Workflows
#1: Get workflow initiator information in SharePoint hosted Add-in
#2: How to check if sharepoint group exists in Visual Studio 2013 workflows
#3: How to get users from SharePoint Group in Visual Studio 2013 workflows
#4: Initiation form in Visual Studio 2013 workflows
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).
Fig1: Rest call for getting user information from Product Owners group.
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";
In step 2, we are making Rest call using HttpSend activity to get the users data in JSON format.
In Step 3, we are using the response from HttSend activity and get the results data into a dynamicvalue.
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.
Fig 2: Getting Users Email address and storing in a collection object.
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.
Step 6 is a sequence which consists of Steps 7, 8 and 9.
In Step 7, we are using GetDynamicValueProperty<System.string> activity to capture Email property of each Item.
In this step, we are adding each user email to the collection defined in Step 4.
In this step we are logging Users email data to workflow history.
Below is the list of variables we have used within the workflow.
Once you are done with workflow, lets start testing it.
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.
You can download the source code by clicking on images below.
In this post, you have learned how to get users from SharePoint group in Visual Studio 2013 workflows.
SharePoint › Tutorials › How to get users from sharepoint group in visual studio 2013 workflows
About Author | |
![]() |
Devendra Velegandla is a five-time recipient of Microsoft's Most Valuable Professional (MVP) award (2014-2019) for Office Apps and Services, 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. |