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

Single email with multiple items from SharePoint list

Hello Community,

 

I have following Sharepoint list:

CristianF_0-1637229664379.png

and following flow:

CristianF_2-1637229970100.png

CristianF_4-1637230103339.png

 

The flow is supposed to send an email with last 24 hours items created in SharePoint list.

The issue with my flow is that for given example of the list with 2 entries, the flow is sending 2 separate emails with the informations:

CristianF_5-1637230605565.png

I want to make the flow to send only one email and duplicate the table with the informations.

 

Thank you in advance !

BR,

CristianF

1 ACCEPTED SOLUTION

Accepted Solutions
efialttes
Super User
Super User

Hi!
Your problem is... 'Send an email' action block is currently inside your 'Apply to each' action block, meaning if two items are to be reported, 'Apply to each' iterates two times, and since 'Send an email' is inside, two emails are sent.
So, you need a different design strategy, that is, to initialize a variable of type string to store the HTML table code, add new HTML table rows to that variable in every iteration of the 'Apply to each' ... and then add 'Send an email' outside the apply to each, assigning the variable inside the body
Anyway, I believe there is a fastest easiest way to achieve your goal that is to replace 'Apply to each' and use either 'Create HTML table' action block  or 'SElect + Create HTML tble' action blocks instead. If you want to explore this suggestion, you will find great stuff hre
Power Automate create an HTML table - EnjoySharePoint
¡Animo!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

5 REPLIES 5
efialttes
Super User
Super User

Hi!
Your problem is... 'Send an email' action block is currently inside your 'Apply to each' action block, meaning if two items are to be reported, 'Apply to each' iterates two times, and since 'Send an email' is inside, two emails are sent.
So, you need a different design strategy, that is, to initialize a variable of type string to store the HTML table code, add new HTML table rows to that variable in every iteration of the 'Apply to each' ... and then add 'Send an email' outside the apply to each, assigning the variable inside the body
Anyway, I believe there is a fastest easiest way to achieve your goal that is to replace 'Apply to each' and use either 'Create HTML table' action block  or 'SElect + Create HTML tble' action blocks instead. If you want to explore this suggestion, you will find great stuff hre
Power Automate create an HTML table - EnjoySharePoint
¡Animo!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

CristianF
Helper I
Helper I

Hi @efialttes,

Many thanks for your fast reply !

I managed to get the flow working as desired with fastest easiest way by using action block 'Create HTML Table', but to be honest i don't really like the outcome received on email 😁.

I switched the stategy to initialize HTML code in variables, but i'm doing something wrong and i cannot save the flow since i'm getting error: Flow save failed with code 'InvalidVariableOperation' and message 'The inputs of workflow run action 'SetCodes' of type 'Compose' are not valid. The variable 'TabelCode' must be initialized before it can be used inside action 'SetCodes'.

Can you please tell me what am I doing wrong ? 

CristianF_0-1637234697213.png

CristianF_1-1637234750565.png

CristianF_2-1637234858897.png

Expression used inside 'SetCodes' 'Compose' block: replace(replace(replace(replace(replace(variables('TabelCode'), '%data1%', items('InitializeReplacements')?['Date']), '%data2%', items('InitializeReplacements')?['PhoneNumber']), '%data3%', items('initializeReplacements')?['Model/Value']), '%data4%', items('InitializeReplacements')?['TipComanda/Value']), '%data5%', items('InitializeReplacements')?['User/DisplayName'])

efialttes
Super User
Super User

Hi!
The variable name you declared is TableCode and not TabelCode, right? Check again your expressions, sounds like a typo...



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Oh...stupid mistakes were made ! 😅

Corrected names and now everything is working like a charm !

Thank you very much for your kind support !

CristianF
Helper I
Helper I

As mentioned above the flow is working but I am getting back with another issue;

As you saw in the initial post there is a Filter Query set in 'Get Items' action that is set to: Created ge 'addDays(utcNow(),-1)' which is also working and sending the email notification only for items that are in the list no older than 24 hours.

My issue is that the flow is still sending the email (with no data, but it's sending it) even if there are no items that surpasses the Filter Query.

 

Is there a way to set a sort of a condition that will be setted only if Filter Query is applied ?

Or if there are other solutions they are welcome !

Helpful resources

Announcements
Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Users online (1,422)