web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Help needed building a...
Power Automate
Answered

Help needed building a flow for use in Copilot Studio which uses For Each loop

(1) ShareShare
ReportReport
Posted on by
Hello Everyone.
 
I have a made a custom Copilot that asks the user for their email address.  That is then stored.  I want to pass that variable to a Power Automate flow that reads a spreadsheet, does something if the email address from the custom Copilot is in the spreadsheet and then feeds the output back to Copilot Studio.
 
Here is what I have so far.
 


The flow runs from Copilot and lists all rows present in a table.

The table looks like this
 

It has an Apply to Each.

 
It has a condition that checks if the input from Copilot matches the Email column.



The issue here now is what do I put under the True section?

If I put the Respond to Copilot node, it gives the error below when I try to publish it:



Flow client error returned with status code "BadRequest" and details "{"error":{"code":"InvalidOpenApiFlow","message":"Flow save failed with code 'InvalidWorkflowRunAction' and message 'The workflow run action 'Respond_to_Copilot' has type 'Response' that could not be nested under an action of type 'foreach'.'."}}".

So, if I move Respond to Copilot, like below, out of the ForEach scope I can no longer access any variables from the spreadsheet.


So, if I then try to add the variables back, it creates a ForEach again and the error comes back, and I cannot save.

 
 
How can I solve this?

The flow should work like this:

1 - Take in the user_email input from the Copilot I made
2 - Read through all rows in my Excel spreadsheet
3 - Check if the user_email input is in the Email column of the spreadsheet
4 - If yes, get the DB_Name and Permissions from the spreadsheet that match it and covert those variables to String to give back to Copilot Studio,
5 - Send those String variables back to the copilot through the outputs of the Respond to Copilot node.

Many thanks.
Categories:
I have the same question (0)
  • Verified answer
    Manish Solanki Profile Picture
    15,167 Moderator on at
    Hi,
     
    Just delete the loop created for responding to copilot as it is not needed.
     
    Add 'Initialize variable' action to declare a string variable at the start of the flow lets says 'UserEmail'. In true branch, set the value of variable by passing email value from the dynamic output of excel row.
     
    At the end of the flow (outside apply to each action), just pass the value of variable in 'Respond to copilot' action.
     
    Save the flow & retest it.
     
     
     
     
     
    Thanks

    If this helps & solves your problem, please remember to like this reply and accept my solution as it will help others in the future.
     
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 594

#2
Valantis Profile Picture

Valantis 328

#3
David_MA Profile Picture

David_MA 281 Super User 2026 Season 1

Last 30 days Overall leaderboard