cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MaverickSpore
Frequent Visitor

Reducing How Many Emails Are Sent Based on File Owner

I have a flow that currently will send an email for every expired file. However, I want to combine them, so all files under the same Owner will be sent together, in one email, instead of each file having it's own email. So I need to figure out how to send more then one item per email, based on the Owner DisplayName field. Any Ideas?

 
1 ACCEPTED SOLUTION

Accepted Solutions

(Let's see if it will allow me to post the images)
I ended up going a different route, which seems to be working so far! by using the orderBy field on getFiles (your way wasn't quite working right, as I'm getting file properties, not items from a list, sorry, my bad on communicating that when i said list instead of library on accident)

LessEmailsWorking1.pngLessEmailsWorking2.pngLessEmailsWorking3.pngLessEmailsWorking4.png

View solution in original post

10 REPLIES 10

@MaverickSpore 

Is the list of owners static or will those people change?  I was thinking you could have a separate branch for each owner which filters their list and sends an email.  That's one way, but there are probably a couple of ways to approach this.

 

-Ed

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

It might be, but if possible it would be better to create it in a way that is can be more dynamic. I was considering doing loops, but I would need to initialize a variable in the loop for the plan I had, and that is a now-go with flow.

A separate branch for each one would make sense, but that would likely not work as well dynamically.

@MaverickSpore 

The loop isn't totally dead.  What were you thinking about trying?  You could initialize the variable before the loop and then update inside.  I was thinking you could lead off by creating an array of active owners, and then cycling through each one inside the loop, is that sort of what you had in mind?

 

-Ed

I was going to create an array variable inside the loop, using each owner as a new array. thus, the (random numbers for example) 15 items with 3 total owners, would combine into 3 arrays, then could be placed into emails respectively. That, however, would require new variables to be initialized inside of the loop, as there's no way of telling how many owners there might be at the time of the flow running.

Ok, I understand.  Following that same path again, you can Initialize the variable at the top of your flow (before the loop) and then Set the variable inside.  I think I have an idea for a solution but want to test it first.  How are you getting the 'expired files'?  Is this all in a SharePoint library or something?

 

-Ed

From a SharePoint list, using Get Items (Properties Only)

@MaverickSpore 

Hey there - Checking in:  I've got something that is pretty close, just tidying it up a bit and then will document it for you.  I'm going to spend some time to see if I can speed the process up (it's not super fast right now).

 

Anyway, keep us posted on your progress and I'll check back in when I've got this one figured out, as well. 🙂

 

-Ed

@MaverickSpore 

Ok, here we go:

There are two "tricks" to make this work.  The first is using a Sharepoint HTTP GET to get all of the owners of your documents.  You can include the expiration date as part of your OData filter to only get a list of items for expired docs, right?  Here is how mine is set up...

 

The next trick is to do a self-referencing Union() to get the unique values from that list.  I put this expression in a Compose action:

union(body('Send_an_HTTP_request_to_SharePoint')?['value'],body('Send_an_HTTP_request_to_SharePoint')?['value'])

 

20200409b.PNG

 

Depending on your comfort level, you can skip the next step, but I added a Parse JSON step so that I was only grabbing the values of the email/owner column (and NOT the header).  I didn't write the code in there, I used "Generate from Sample" - lots of articles on this action out there, if you are unfamiliar with it:

20200409c.PNG

 

Then, I used the Get Items SharePoint action and pointed it to my list.  In the OData filter area, you'll put your owner column, then "eq" (no quotes) for equals, and then the value from your Parse JSON step.  This will trigger an Apply to Each loop, which is what we want.

20200409d.PNG

 

After that (but still inside the Apply to Each loop), I added a Select action to only get the columns I wanted from the SP list, and then converted that to an HTML table to include in my email body (the "Output" shown is from the "Select 2" action prior):

 

20200409e.PNG

 

Finally, still inside the loop, I send the email.  This means that an email will be sent for each 'owner' and include the records for that owner in the HTML table body (shown below as "Output").  You'd swap out my name in the To: field with the dynamic value of the Owner from your Parse JSON step.  

20200409f.PNG

 

This resulted in 2 separate emails (I only had two different owners for the 10 items in my SP list) and each included the appropriate items for each.

 

Hope that helps.  Keep us posted.

-Ed

 

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

ScottShearer
Super User
Super User

@MaverickSpore 

Here is a link to a thread which I believe has a solution to your issue.

 

 

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

(Let's see if it will allow me to post the images)
I ended up going a different route, which seems to be working so far! by using the orderBy field on getFiles (your way wasn't quite working right, as I'm getting file properties, not items from a list, sorry, my bad on communicating that when i said list instead of library on accident)

LessEmailsWorking1.pngLessEmailsWorking2.pngLessEmailsWorking3.pngLessEmailsWorking4.png

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,111)