cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Frequent Visitor

Re: Reducing How Many Emails Are Sent Based on File Owner

(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
Highlighted
Super User
Super User

Re: Reducing How Many Emails Are Sent Based on File Owner

@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.

Highlighted
Frequent Visitor

Re: Reducing How Many Emails Are Sent Based on File Owner

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.

Highlighted
Super User
Super User

Re: Reducing How Many Emails Are Sent Based on File Owner

@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

Highlighted
Frequent Visitor

Re: Reducing How Many Emails Are Sent Based on File Owner

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.

Highlighted
Super User
Super User

Re: Reducing How Many Emails Are Sent Based on File Owner

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

Highlighted
Frequent Visitor

Re: Reducing How Many Emails Are Sent Based on File Owner

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

Highlighted
Super User
Super User

Re: Reducing How Many Emails Are Sent Based on File Owner

@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

Highlighted
Super User
Super User

Re: Reducing How Many Emails Are Sent Based on File Owner

@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.

Highlighted
Super User
Super User

Re: Reducing How Many Emails Are Sent Based on File Owner

@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
Highlighted
Frequent Visitor

Re: Reducing How Many Emails Are Sent Based on File Owner

(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
firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Users online (9,651)