cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DavyNix
Helper I
Helper I

Flow to send only one Email per scheduled trigger

Hi All,

Built a flow which reads file names found in a SP folder (library), adds them to a HTML table, which it embeds into a nicely formatted Email and then finally moves the files on to another folder.  I had a problem in that the Email would send even when the folder was empty.  Got some help from the community to add a condition which seemed to work. 

DavyNix_0-1627897192683.png

Unfortunately after some further testing, I realised the flow now generates a separate (identical) Email for each file it finds in the folder.    I've solved one issue and gained another!  Any ideas how to tackle this?

 

Thanks - David.



2 ACCEPTED SOLUTIONS

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

So since there is only one line per filename then the Apply to each loop processing each file should only be adding that filename to an array variable.  Once the loop has processed all the files then you can convert the array variable to an HTML table and send the email.



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

View solution in original post

DavyNix
Helper I
Helper I

Hi @Pstork1 the issue I found is that the create HTML table wasn't able to read the array created within the apply to each.   I found a simple workaround.  I set the check for items value to greater than 1.  So anything other than the hidden folder triggers the rest of the flow to complete.

 

Thanks for your help.

View solution in original post

12 REPLIES 12
Pstork1
Dual Super User III
Dual Super User III

Can you provide a screenshot of where in your flow you send the email?  I suspect you are getting multiples because you send the email inside the loop instead of after you finish processing all the files.



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

Hey - thanks for the reply:

 

DavyNix_0-1627921223178.png

 

Pstork1
Dual Super User III
Dual Super User III

I don't know exactly what you need to do without seeing your actual data.  But basically you'll need to move the Create HTML table and send email outside the loop that is processing the files.  Inside the loop you'll need to aggregate the data into one array using some form of append to array where you are doing the Create HTML table now.  In the table you are creating now, does it create multiple lines per file or just one line?  I'm not sure what you are using the filter array step for.



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

Hi @Pstork1 ,

 

Thanks, I'll explain from the from the top! Grab a coffee...

 

The requirement is to list the contents of the folder into a nicely formatted Email and then move the files to another folder once complete.  Flow should send only if the folder has files and should only send 1 Email listing all files.
Email generates well:

DavyNix_0-1627988275019.png

Flow:

1. Reoccurring Trigger
2: List the contents of the folder

DavyNix_1-1627988447020.png

From here on everything sit's within an apply to each:

 

3. Check length of output from step 2 to confirm folder contains files

length(outputs('List_folder')?['body'])
DavyNix_2-1627988570218.png

4. Discount folders

 

From here on it's just case of generating the HTML table to place inside the body of the Email.

 

DavyNix_4-1627988792587.png

So the logic feels simple but I don't know how to structure the the Flow so that the Email generation sits outside of the 'apply to each'.  Very to new to Power Automate as you may have guessed.

Thanks for your help!

Pstork1
Dual Super User III
Dual Super User III

So since there is only one line per filename then the Apply to each loop processing each file should only be adding that filename to an array variable.  Once the loop has processed all the files then you can convert the array variable to an HTML table and send the email.



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

View solution in original post

So create HTML and Email should just be outside of the loop?  I'll go try that.

Well that was embarrassingly simple - Thanks @Pstork1 

DavyNix
Helper I
Helper I

@Pstork1  - actually I spoke too soon.  I'm back to my original problem.  The Email now sends even if the folder is empty.  This was the reason for adding:

DavyNix_0-1628006853757.png

The proceeding actions outside of the 'apply to each' do not seem to to interact with with anything inside the 'apply to each'.  For example I can't use the array I created to build the HTML table.

DavyNix_1-1628007252707.png

 

Does the condition which checks for file have to sit within an apply to each?  This is what's causing all of my problems.  

DavyNix_2-1628007357930.png

Thanks,

DavyNix
Helper I
Helper I

I think what's happening is that the 'IsFolder 'condition must sit inside an 'apply to each'.  If I don't have the 'IsFolder' then the Email sends anyway as the main folder contains a sub folder called 'forms' which I don't seem to be able to delete or even see via sharePoint.

so frustrating...


Pstork1
Dual Super User III
Dual Super User III

Once you've taken the Send email out of the Apply to each loop you need to put a condition around it to test if the array has anything in it before converting it to HTML and sending it.  Its possible that the apply to each runs and doesn't find any files.  In that case the array will be empty and the email shouldn't be sent.



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

Hi @Pstork1 the issue I found is that the create HTML table wasn't able to read the array created within the apply to each.   I found a simple workaround.  I set the check for items value to greater than 1.  So anything other than the hidden folder triggers the rest of the flow to complete.

 

Thanks for your help.

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

You aren't supposed to create the table inside the apply to each.  You need to build the array and once its complete (after exiting the apply to each) then you build the HTML table from the array.



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

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!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (2,611)