cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Dorinda
Super User
Super User

Send email using flow to Multiple SharePoint groups at once

I have a flow that can send an email to one SharePoint Group at a time, is there a way to have it send it to them all at once.  This is for a reminder email that goes out twice a month, and each of the SharePoint groups need to have it sent, I do not want to build 30 flows, I suppose i could do a Parallel branch but i still have to rinse and repeat the entire thing.

 

Any suggestions?

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions

This is how the flow should be structured if you include 'Get items' and using the output from 'Get items' in the email. 

image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

29 REPLIES 29
tom_riha
Super User
Super User

Hello @Dorinda ,

maybe you could use a loop in the flow. I don't know what your flow looks like, but if you need to repeat the same set of actions, you can initialize an array variable with the input (I guess the SP groups in your case), and use 'Apply to each' to loop through the array with the SP groups and repeat the actions for each of them.image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

With the flow I am using it calls it is using this in the HTTP call _api/Web/SiteGroups/GetByID(161)/users, how do i apply your idea to call each Site Group ID?

@Dorinda  I think so it will work. I did not test this. Pass all group IDs in array as @tom_riha  suggested. For each group ID make your HTTPS connection URI -->Parse JSON:

Hardesh15_0-1612450496973.png

For each group ID it will add all emails in Group variable which you can use in email.

 

Please 'Thumbs Up' the posts that helped you and 'Mark as Solution' if my post answered your question.

@Hardesh

 

so i have to rebuild it all over then, i am not following. Sorry

@Dorinda  Thank you !!!

Not sure why you are thanking me, I have not solved my issue at all!!

Hello @Dorinda ,

first step is to put all the Site Group IDs into an array variable. The input must consist of opening [ , closing ] and comma separated values in quotes. You must enter all the IDs manually.

[
  "GroupID1",
  "GroupID2",
  "GroupID3"
]

Once you have the IDs in the array, you can use 'Apply to each' to loop through that array. 'Apply to each' will take the GroupIDs from the array one by one and give you the value in the 'Current item' dynamic content. You should use the 'Current item' dynamic content as the group ID in the HTTP call.

And also the rest of the process you need to repeat for each of the groups must be inside that 'Apply to each'. image.png Example how it'll work with the array above:

 

  • 'Apply to each' 1st loop: 'Current item' = GroupID1; HTTP request: '_api/Web/SiteGroups/GetByID(GroupID1)/users'
  • 'Apply to each' 2nd loop: 'Current item' = GroupID2; HTTP request: '_api/Web/SiteGroups/GetByID(GroupID2)/users'
  • 'Apply to each' 3rd loop: 'Current item' = GroupID3; HTTP request: '_api/Web/SiteGroups/GetByID(GroupID3)/users'


[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

So I have not errors and it appears to be working to send emails to me but the other members of the groups didnt get anything.  It is showing that it is going through the different groups, but I am the only one getting emails.

 

Dorinda_0-1612479106001.png

I have more groups just didnt want to run them all at once until i knew it was working.

@tom_riha @RandyHayes,

 

Hi wondering if you can provide additional guidence why it is not sending emails to all of the users in the SP Group?  There are three in each at the moment and I am the only one getting the emails.

 

Thanks in advance.

Dorinda

Hello @Dorinda ,

it's hard to tell without seeing what your flow looks like. Can you share a screenshot?



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

Here you go

step1.png

step2.png

step3.png

I'd say your flow is more complicated than it needs to be, you're combining both of the approaches mentioned in this thread and I'm a bit lost in it. 🙂 I'd do it as on the screenshots below:

image.png

image.png

If you need to repeat the same process for multiple items (I see you're using 'Get items' in the flow), then the whole 'Apply to each' part on the screenshot above must be inside another 'Apply to each' where you'll process the items one by one.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

I sorta started over as you instructed.  

 

I am getting the following error

 

The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')?['properties']?['properties']?['properties']?['d']?['properties']?['properties']?['properties']?['results']' is of type 'Null'. The result must be a valid array.

Dorinda_0-1612544444011.png

Dorinda_1-1612544481212.png

 

 

this is what is in my json

 

{
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"d": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"results": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"id": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"uri": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"Alerts": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"uri": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"Groups": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"uri": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"Id": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"IsHiddenInUI": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"LoginName": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"Title": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"PrincipalType": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"Email": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"IsEmailAuthenticationGuestUser": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"IsShareByEmailGuestUser": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"IsSiteAdmin": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"UserId": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"NameId": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
},
"NameIdIssuer": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"type": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"required": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

@tom_riha 

I found your blog and followed your instruction to get the JSON, however this is now the error I am getting

The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')?['properties']?['properties']?['properties']?['d']?['properties']?['properties']?['properties']?['results']' is of type 'Null'. The result must be a valid array.

 

 

@tom_riha 

 

Ok I got it fixed and it WORKED!!, my only question goes back to why I needed the Get Items, is i thought I needed that to get the items from the Calendar that is when the recurrence needs to know the dates to run.  It needs to run on the 10th and the 15th of each month is there an easier way to do this?

 

Also I got 28 emails when i just should have gotten three so I am not sure why that happened.

 

I spammed my co-workers but i am so happy it is working!!

Dorinda

Something is probably looping too many times. 🙂 

To run the flow only on 10th and 15th each month I'd use a trigger condition (3 dots on the action -> settings). Schedule the flow to run daily with a trigger condition that will check if the 'days' part from today's date is 10 or 15. If true, run the flow, otherwise don't do anything.

@or(equals(int(utcNow('dd')),10),equals(int(utcNow('dd')),15))

image.png

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

How do I find what is looping?  It is built just like you showed me

Check the run history of the flow, the 'Apply to each' actions, you'll see how many times which of them did run.

The solution I shared is looping through all the SP groups in that array and sending an email to each of them. If you placed it inside another 'Apply to each' based on the 'Get items' then maybe you're getting more items from the list and repeat the email sending part more than you thought.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (4,490)