Safe access with the ? operator
Quiz question
What does item()?['id'] return when the property id is missing?
Solution
- A) The value null, and the flow keeps runningCorrect. The question mark turns a missing property into null instead of failing the action.
- B) An error that stops the action immediatelyWrong. That happens without the question mark: item()['id'] fails with InvalidTemplate.
- C) The value of the previous item in the arrayWrong. The expression only reads the current item and takes no values from other items.
What it is about
Data from lists, emails or APIs is rarely complete. An expression like item()['id'] assumes that the property id always exists. If it is missing in a single item, the action fails with the error InvalidTemplate. With a question mark before the bracket, item()?['id'], the expression returns null in that case instead of an error. The question mark only protects the bracket it stands in front of. For nested paths you therefore put it before every level. Then you decide what should happen with null, for example with coalesce() and a fallback value or with a Condition. The question mark does not help against a wrong data type.
The expression from the tip
item()?['id']When to use it, when not
Use it
Whenever you read data whose fields are not always present, such as API responses or optional list columns.
Better not
When a missing field is a real error you want to see. Then the action should fail.
Most common mistake
Setting the question mark only on the first level. triggerBody()?['missing']['x'] still fails when missing is absent.
License
Standard Runs without a premium connector, so the license from Microsoft 365 is enough. Source on Microsoft Learn: Power Automate licensing FAQ. For your whole flow: License check.
Share
Short link: powerautomate.ninja/en/59
Source: PowerPlatformTip #59, Microsoft Learn: Workflow Definition Language schema reference.