Item vs Items in PowerAutomate
- Get link
- X
- Other Apps
π‘ Meaning of items() in Power Automate
In Power Automate,
items() is a function that represents the current item being processed inside a loop, such as an Apply to each action.
Think of it like this π
If you have a list of rows and Power Automate loops through them one by one —
items() refers to the single row currently being processed.
π§© Example
Suppose:
Your “List rows” (List_rows_1) returns:
{
"body": {
"value": [
{ "fullname": "John Doe", "emailaddress1": "john@contoso.com" },
{ "fullname": "Jane Smith", "emailaddress1": "jane@contoso.com" }
]
}
}
You then add an Apply to each action:
Apply to each: value = outputs('List_rows_1')?['body/value']
Inside this loop:
-
On the first iteration,
items()={ "fullname": "John Doe", "emailaddress1": "john@contoso.com" } ``` -
On the second iteration,
items()={ "fullname": "Jane Smith", "emailaddress1": "jane@contoso.com" } ```
π― Using items() Inside the Loop
| You Want | Expression |
|---|---|
| Full Name | items('Apply_to_each')?['fullname'] |
items('Apply_to_each')?['emailaddress1'] |
If your loop name is something else (say Apply_to_each_2), use:
items('Apply_to_each_2')?['fullname']
π§ Analogy
You can think of it like:
for each record in list_of_records: current_record = items()
So items() = the current record being processed in the loop.
Would you like me to show the difference between items() and item() (they’re similar but used in slightly different contexts)?
You said:
ChatGPT said:
Perfect π — this is a subtle but important distinction in Power Automate.
Let’s break down the difference between item() and items(), when to use which, and why both exist.
⚖️ Difference Between item() and items()
| Function | Used In | Meaning | Example Use |
|---|---|---|---|
item() | Inside a nested action (like inside a “Filter array”, “Select”, or “Apply to each”) | Refers to the current record being processed in that specific loop or data operation | item()?['fullname'] |
items('LoopName') | When referring to a specific loop’s current item from outside or nested inside another loop | Refers to the current item of a specific “Apply to each” action by its name | items('Apply_to_each')?['fullname'] |
π§© Example 1 — Basic “Apply to each”
You have:
Apply to each: value = outputs('List_rows_1')?['body/value']
Inside the loop:
✅ Both work the same:
item()?['fullname']
or
items('Apply_to_each')?['fullname']
However, Power Automate usually auto-generates the second version:
items('Apply_to_each')?['fullname']
because it’s more explicit — it tells which loop it belongs to.
π§© Example 2 — Nested Loops (Inner + Outer)
Let’s say you have two loops:
-
Outer Loop:
Apply_to_each_Contacts -
Inner Loop:
Apply_to_each_Orders
Now you want to access:
-
The current Order → that’s from the inner loop
-
The current Contact → that’s from the outer loop
| You want | Expression |
|---|---|
| Field from Order (inner loop) | item()?['orderid'] |
| Field from Contact (outer loop) | items('Apply_to_each_Contacts')?['fullname'] |
✅ Here’s why:
-
Inside the inner loop,
item()means “current order”. -
To refer to the outer loop’s item (contact), you must use
items('Apply_to_each_Contacts').
π§ Analogy (Simple Mental Model)
for each contact in Contacts: for each order in Orders: // item() = current order // items('Apply_to_each_Contacts') = current contact
⚡ TL;DR Summary
| Use Case | Use |
|---|---|
| Inside a single loop (not nested) | item() or items('Apply_to_each') both fine |
| Inside nested loops | item() → inner loop item; items('LoopName') → specific outer loop item |
| Outside of the loop | Only items('LoopName') works |
| Inside “Select” / “Filter array” / “Map” | Use item() |
- Get link
- X
- Other Apps
Comments
Post a Comment