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

Apply To Each Causing Email Notification Failure

Hi all,

I've got a flow to check for a future date of 14 days to sweep a Sharepoint list for upcoming deadlines.  I want it to ping the person it is assigned to with an email notifying them (I have to use v3 mail due to restrictions at the organisation).

 

When I get to the condition to check if there are any true records and if yes send the mail, I get the below error.  I get that the issue is lying in the 'Apply to Each' output.  I've tried 'Value' 'Body' and the array expression 'array(triggerOutputs()?['body'])'.


When I run the first two variations, I get versions of the below error.  When I try the array expression it skips the email action, so it runs 'successfully' but doesn't do what I need it to.  Any ideas on what I'm doing wrong?  Thanks! 

 

Step 1.jpg

Step 2.jpg

3.jpg

10 REPLIES 10
Pstork1
Dual Super User
Dual Super User

Current item from the outer loop isn't an array, its an object.  You don't need the inner loop, just use the email in the yes side of the condition.



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

Sorry, I should have said when creating the condition, whenever I put the 'By Whom Email' in the email template on the yes side, that is when it creates the 'Apply To Each 2'.  Its as if the Apply to Each 1 and 2 aren't working together correctly. 

David-
Solution Sage
Solution Sage

I have also seen this error when your get items returns no items. You should add a variable (Count) of integer type. After the get items action set the Count variable using the length expression to tell you how many items were returned. Then add a condition where Count is greater than zero. You can then continue with your flow under the Yes side of the condition. On the no side you could send yourself an e-mail that not items were found matching the filter or just let the workflow end.

 

David_0-1657802164468.png

 

nm1979
Frequent Visitor

Hi David,
Thank you for responding, when I try that length expression as you suggest it says 'Unable to process template language expressions in action 'Set_variable' inputs at line '0' and column '0': 'The template language function 'length' expects one parameter: an array or a string the length of which is returned. The function was invoked with '0' parameters. Please see https://aka.ms/logicexpressions#length for usage details.'.'

Which then prompts the 'Apply To Each' to skip again.

The following is the expression to calculate how many items were returned:

 
length(outputs('Get_items')?['body/value'])
nm1979
Frequent Visitor

Hi David,
Thank you.  The variables additions now works, but it hasn't resolved the original issue of 'Send an email notification' not triggering.  In fact, when I come to edit the 'Send an email notification (V3)' template, I can now no longer pull emails from the 'By Whom' column (which is subsequently pulling those email addresses from our directory) as it no longer gives me it as an option in the Dynamic Content.

I'm not clear on what you are saying.  In your screenshot the condition is based on ByWhen, not By Whom?  Is By Whom a multichoice people field?  That would be why its adding the second loop.  If it is a multichoice field you should be converting it into a semicolon string of email addresses instead of using it directly.  Also, By Whom will actually be people objects.  You need to look for By whom email.



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

Hi,
So to my mind, I've got the flow to get items which have an upcoming due date 14 days from now.  Once it has found those by the ODATA query, I want it to then email the person who this item is actionable by in the By Whom column, but its falling down here, because by selecting the 'By Whom Email' (which it is pulling from the By Whom people column and our directory) its unable to do this due to the aforementioned error.

Unless the By Whom is set to allow multiple selections this should work exactly as described.  If By Whom is set to allow multiple selections then you need to process the By Whom Emails into a string first.  If the By Whom isn't set for multiple selections then it shouldn't be adding the inner Apply to each.  Is By Whom set to allow multiple selections?



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

I've reworked the whole thing and got it working pulling some ideas from this video aswell as taking on board some of the comments laid out here regarding columns. 
Flow now looks as follows furthering the ODATA query specification to only include items that are still 'in progress' but then using Select to draw the By Whom email addresses out.  All tested and all working as I wanted.

14 Day Flow.jpg

 

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!

Top Solution Authors
Top Kudoed Authors
Users online (3,576)