cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KevZF
Regular Visitor

Nested for each loop problem

Hello Proffessionals!

I made a functioning Approval Flow using Power Automate, but when trying to parse a json i get following error.

So my goal is to attach the Links from the forms attachments and only having the Link in the approval Flow, thats why i'm trying to implement the json step.

The error says that it'S not possible to have nested for each loops. How can I add the Json step withouth getting this error?

KevZF_0-1659951150514.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
MarconettiMarco
Super User
Super User

Hello @KevZF ,

in order to avoid the first apply to each to get the attachments links, please follow these steps:

1. Initialize an Array variable:

MarconettiMarco_0-1659959559541.png

 

2. Get response details from the Trigger:

MarconettiMarco_1-1659959578256.png

 

3. Add a "Compose" action in which put the following expression:

 

 

json(outputs('Get_response_details')?['body/rb8620b6b2c4e4eb181de495f2886511e'])

 

 

Instead of "rb8620b6b2c4e4eb181de495f2886511e", please specify your attachment question.

MarconettiMarco_2-1659959619105.png

4. Add an "Apply to each" control from the previous Compose outputs and within add an "Append to array variable" action, putting the following expression:

 

 

item()?['link']

 

 

MarconettiMarco_3-1659959719710.png

5. Outside from the apply to each, you can check how is filled you variable by adding a Compose action:

 

join(variables('varDocUrl'),',')

 

MarconettiMarco_6-1659960727863.png

 

Here my output:

MarconettiMarco_5-1659959830202.png

 

So, you can put the variable in the "Item link" field within the "Start and wait for an approval" action.

 

Otherwise, and I suggest the following solution, it should be preferrable to attach the docs to the Approval email:

 

https://www.bythedevs.com/post/working-with-files-on-ms-forms-in-ms-power-automate

 

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

BR,

Marco

 

 

 

 

View solution in original post

13 REPLIES 13
MarconettiMarco
Super User
Super User

Hello @KevZF ,

in order to avoid the first apply to each to get the attachments links, please follow these steps:

1. Initialize an Array variable:

MarconettiMarco_0-1659959559541.png

 

2. Get response details from the Trigger:

MarconettiMarco_1-1659959578256.png

 

3. Add a "Compose" action in which put the following expression:

 

 

json(outputs('Get_response_details')?['body/rb8620b6b2c4e4eb181de495f2886511e'])

 

 

Instead of "rb8620b6b2c4e4eb181de495f2886511e", please specify your attachment question.

MarconettiMarco_2-1659959619105.png

4. Add an "Apply to each" control from the previous Compose outputs and within add an "Append to array variable" action, putting the following expression:

 

 

item()?['link']

 

 

MarconettiMarco_3-1659959719710.png

5. Outside from the apply to each, you can check how is filled you variable by adding a Compose action:

 

join(variables('varDocUrl'),',')

 

MarconettiMarco_6-1659960727863.png

 

Here my output:

MarconettiMarco_5-1659959830202.png

 

So, you can put the variable in the "Item link" field within the "Start and wait for an approval" action.

 

Otherwise, and I suggest the following solution, it should be preferrable to attach the docs to the Approval email:

 

https://www.bythedevs.com/post/working-with-files-on-ms-forms-in-ms-power-automate

 

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

BR,

Marco

 

 

 

 

Hello Marco,

 

thank you so much for the answer!
When I try to add the "2. Get response details from the Trigger:",

power automate automatically adds another "apply to each" loop.

Should I add the steps after that to that loop?

Kind regards
Kev

Hello @KevZF ,

PA should not automatically create an Apply to each loop. Have you simply added the Response ID like below?

MarconettiMarco_0-1659968047612.png

 

 

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

BR,

Marco

Hey Marco,

 

today it worked without PA putting in the apply each loop.
I tried replicating your solution but somehow i still get following error : 

KevZF_0-1660027856203.png


my Flow looks like this : 

KevZF_1-1660027901779.png


the only thing I see that is different to your Flow, is the Value in the append to array variable.
I copied what you put into there but somehow the step doesn't recognize the link?

Kind regards

Kev

 

Hello @KevZF ,

in the "Append to array" action, you should put "item()?['link']" as expression, not as free text.

 

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

BR,

Marco

This worked out, thanks!

KevZF_0-1660028450118.png

somehow I still get an error...

KevZF_1-1660028492571.png


Kind regards

Kev

Hello @KevZF ,

in the Compose action you should put this expression as an expression, not as free text:

json(outputs('Get_response_details')?['body/rb8620b6b2c4e4eb181de495f2886511e'])

 

MarconettiMarco_0-1660028675744.png

 

 

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

BR,

Marco

Hey Marco,

thanks for the quick replys and sorry for the inconvenience, but I can't seem to make it work! 😞

 

KevZF_0-1660029245233.png


I did put this in as a expression : 

json(outputs('Get_response_details')?['body/rb8620b6b2c4e4eb181de495f2886511e'])



Hello @KevZF ,

you've to replace "rb8620b6b2c4e4eb181de495f2886511e" with your question code.

 

The "rb8620b6b2c4e4eb181de495f2886511e" was my question code.

 

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

BR,

Marco

How do I get the question code?

Hello @KevZF ,

please follow these steps:

Presentation1.gif

 

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

BR,

Marco

it worked out, thanks alot!!!

KevZF
Regular Visitor

Hello @MarconettiMarco,

 

I know that this goes beyond this Topic but maybe you can also help me out with this!
So I'm trying to add the attachment links to my approval request.
This is the Flow without the Steps that you showed me: 

KevZF_0-1660034147072.png


In the Flow where I'm trying to merge the steps that you showed me, I can't seem to get the Output I need to put into the apply to each Loop that I marked in the first screenshot.

KevZF_1-1660034241269.png

 

Kind regards

Kev



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.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (3,253)