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

Notifications

Announcements

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
    ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard