In an article published late last year, I described an undocumented CopilotStudio designer element called Foreach
, which is designed to loop through all records in a table object. This element can be used in custom topics to iterate over structured data and get some cool results.
Fast forward to eight months later, I just noticed it is officially added to CopilotStudio's designer. You can find it under Variable Management -> ListManagement
:
Once you add it, the UI looks exactly like late last year's:
In above case I set it up to loop through all records in a table value called GetItems.value
, which is returned from a Copilot Studio tool (used to be called action) to get items from a SharePoint list. The foreach loop variable is called LoopValue1
, its type is record
.
Other cool elements available are "
continue
"
and "
break
"
in a loop:
"
continue
"
in most programming languages, this skips the current loop iteration and starts the next."Skip to next item"
:Here is a code-behind example:
1 id: foreach_1BGYSa
2 items: =Topic.GetItems.value
3 value: init:Topic.LoopValue1
4 index: init:Topic.LoopIndex1
5 actions:
6 - kind: ConditionGroup
7 id: conditionGroup_KEjf8H
8 conditions:
9 - id: conditionItem_bmvAr1
10 condition: =Topic.LoopValue1.Title = "************"
11 actions:
12 - kind: ContinueLoop
13 id: g7a2fq
14
15 - kind: SendActivity
16 id: sendActivity_Ig349K
17 activity:
18 text:
19 - "{Topic.LoopValue1.Title}: {Topic.LoopValue1.Description}"
20 speak:
21 - "{Topic.LoopValue1.Title}"
I am very glad this very useful designer element is officially added to Copilot Studio. Meanwhile, I have found another "minor" undocumented feature which I will blog about in near future.
The content on Invoke, LLC's blog is provided for general informational purposes only and focuses on IT-related topics, including technology trends, software, AI, cybersecurity, and industry commentary. While we strive to provide accurate, up-to-date, and high-quality information, we make no representations or warranties of any kind, express or implied, about the accuracy, reliability, completeness, or suitability of the information, tools, or resources shared on this blog. Any reliance on such content is at your own risk.
The opinions expressed in our blog posts are those of the authors and do not necessarily reflect the official views of Invoke, LLC. Our blog may include links to third-party websites, software, or services. We do not endorse or assume responsibility for the content, functionality, security, or practices of these third-party resources.
The information on this blog is not intended to replace professional IT, technical, AI, or cybersecurity advice. You should consult a qualified IT professional before implementing any solutions, configurations, or strategies discussed on this blog. Invoke, LLC and its affiliates are not liable for any loss or damage, including but not limited to data loss, system downtime, or security breaches, arising from the use of or reliance on this blog’s content.
We reserve the right to modify, update, or remove content on this blog at any time without prior notice.