{"id":110927,"date":"2018-03-22T04:32:39","date_gmt":"2018-03-22T11:32:39","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/fotw-members-your-office365-groups\/"},"modified":"2018-03-22T04:32:39","modified_gmt":"2018-03-22T11:32:39","slug":"fotw-members-your-office365-groups","status":"publish","type":"power-automate","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/fotw-members-your-office365-groups\/","title":{"rendered":"Advanced | Flow of the Week: Get an email with the members of your Office 365 groups"},"content":{"rendered":"
Are you the owner of an Office 365 group that anyone can join, but you still want to, at a glance, understand who is on the group and get some details about them? This flow is for you!<\/p>\n
For this scenario, we\u2019ll create a Button flow that collects a search term from you. It will then find all of the Office 365 groups you own that contain that search term, and list the users for each of those groups. You\u2019ll then get an email with a table of all of the users in each of those groups, along with some details about those users.<\/p>\n
This flow will demonstrate some advanced concepts, including appending to a string variable<\/strong>, building an HTML email<\/strong>, and nested Apply to each<\/strong>.<\/p>\n The flow will start out simple with a Button<\/strong> trigger.<\/p>\n <\/p>\n On the Button trigger, we\u2019ll have one input to collect a search term. Next, we\u2019ll List my owned groups<\/strong> in the Office 365 Groups connector \u2013 and then use Filter array<\/strong>. In the Filter array, on the left side use Add Dynamic Content<\/strong> to find the Name<\/strong> of the group. Use the contains<\/em> operation in the middle, and then use Add Dynamic Content to find the input field you added in the Button trigger. This will return an array that only contains Office 365 Groups which contain the search term you\u2019ll enter when you run the button.<\/p>\n We will build the HTML email by creating a string variable \u2013 a variable is an easy way to collect data each time an action happens inside of a loop. Whenever you use a variable, first you need to use the Initialize variable<\/strong> action. You can name your variable whatever you like, but you need to be sure to set the Type as String.<\/p>\n <\/p>\n The first loop we are going to create is over each of the Office 365 groups returned by the Filter array<\/strong> action. To add this, select New step<\/strong> and then More<\/strong> and Apply to Each<\/strong>. Add dynamic content for the Select an output from previous steps<\/strong>, and you\u2019ll see the original list of groups from the first action, and the filtered list of groups from the Filter array <\/strong>action. Select that list.<\/p>\n <\/p>\n Inside the Apply to each we are going to start constructing the email. For each group we\u2019ll add a heading and the description by using the Append to string variable <\/strong>action. All you need to do is select the variable you created earlier, and then include the content that you want, such as the displayName of the group. Also, for the next step add a new <table> tag at the bottom of the variable.<\/p>\n <\/p>\n Now that you\u2019ve started creating the email, you\u2019ll need to actually retrieve the members of the group. Use the List group members<\/strong> action. In the Group Id<\/strong> field, do not select one of the items in the dropdown, but go to Enter custom value <\/strong>instead. This allows you to Add dynamic content<\/strong> and select the Group Id <\/strong>from the Filter array action (you should search in the Dynamic content window to find this).<\/p>\n <\/p>\n Add the second Apply to each loop like you added the first, but this time select the list from the List group members<\/strong>. \u00a0Inside this loop you\u2019ll add two actions to get more details about the user:<\/p>\n For both of these steps select the User Principal Name <\/strong>from the List group members action.<\/p>\n <\/p>\n The last action inside this second Apply to each loop is to Append to string variable<\/strong> again. This time, you\u2019ll add the contents of each table row you want inside the email. You can include any fields from the user profile, such as a link to their My Site, About Me, or their Hire Date.<\/p>\n <\/p>\n Some of the properties output by Get user profile are lists \u2013 for example a list of interests, schools or skills. You can use the Join<\/strong> action to turn this list into a single string that you can use in the email. You can also use the join()<\/strong> expression to do it inline without having to create a different step. For example, I wanted a list of interests and a list of skills and interests, I\u2019ll show how to do that in an expression.<\/p>\n You\u2019ll need to add one last action into the original Apply to each. Because the first Append to string variable created an HTML table, you\u2019ll also need to close out that HTML table with another Append to string<\/strong> action.<\/p>\n <\/p>\n Now you\u2019re ready to send the email. You should add that action at the very bottom of the flow (if you added it in the Apply to each you\u2019ll get more than one email). In the Send an email notification<\/strong> action you can fill out the To<\/strong> and Subject<\/strong> fields with whatever you\u2019d like. In the Email Body<\/strong>, all you need to do is use the Message <\/strong>\u00a0variable \u2013 it already has all of the groups and tables of their members, so you don\u2019t need to add anything else to the Body.<\/p>\n <\/p>\n Finally, if you want to run this flow from your phone or your desktop, just enter the name of an Office 365 group you own, and you\u2019ll immediately get a list of all of the members of that group \u2013 with helpful details about those members!<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" In this Flow of the Week, learn about how to work with Office 365 Groups and Office 365 Users. This flow will get all of the members of an Office 365 Group you own and send you an email report with those members (with details about each member). It will demonstrate a few advanced concepts like appending to variables , building an HTML email and using nested Apply to each.<\/p>\n","protected":false},"author":347,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","power-automate-category":[2590],"power-automate-tag":[],"coauthors":[2913],"class_list":["post-110927","power-automate","type-power-automate","status-publish","hentry","power-automate-category-flow-of-the-week"],"yoast_head":"\nStarting the Flow<\/h2>\n
Using a string variable<\/h2>\n
Getting the group members<\/h2>\n
\n
Working with lists from Get user profile<\/h2>\n
\n
\n<\/li>\n
\n<\/li>\n
\n<\/li>\nWrapping it up<\/h2>\n