Post

#PowerPlatformTip 59: 'Handle Dynamic Content'

#PowerPlatformTip 59: 'Handle Dynamic Content'

TL;DR: Add the safe navigation operator ? (e.g. item()?['id']) so missing properties return null instead of crashing your flow.

💡 Challenge

When working with Power Automate and dealing with objects or arrays, you often come across expressions like item()['id']. But what if id is not always present in each item? A missing property makes your flow throw an error and fail.

✅ Solution

Use the safe navigation operator ?, for example item()?['id']. It ensures that even if id is missing in some items, your flow won’t crash. Instead of an error, it returns null, which is a lifesaver when your data isn’t always consistent.

🔧 How It’s Done

1. Spot the risky reference

🔸 Find expressions such as item()['id'], body('Action')['value'] or triggerBody()['field'] that assume a property always exists.

2. Add the safe navigation operator

🔸 Insert ? before the bracket: item()?['id'].

🔸 The expression now returns null instead of failing when the property is missing.

3. Handle the null case

🔸 Use coalesce(item()?['id'], 'default') or a Condition to react to missing values gracefully.

Power Automate real flow run: without the safe navigation operator, accessing a missing property crashes the action with InvalidTemplate, while the same lookup with ? succeeds Real flow run: outputs('Sample_Object')['email'] fails outright, “property ‘email’ doesn’t exist, available properties are ‘id, name’”, while outputs('Sample_Object')?['email'] on the identical object succeeds right next to it.

Power Automate real flow run: the safe-navigation lookup succeeds with an empty/null output instead of crashing Real flow run: the ?['email'] version shows Status Erfolgreich with an empty output, null, not an error, exactly the graceful fallback the operator is for.

🧩 Chains, Arrays, Missing vs. null

All results below come from one flow run against this trigger body:

1
{ "name": "Alice", "nested": { "a": { "b": "deep" } }, "nullProp": null, "arr": [1, 2, 3] }

1. Chain the operator on every hop

🔸 triggerBody()?['nested']?['a']?['b'] returns deep.

🔸 triggerBody()?['missing']?['x']?['y'] returns null, the chain stops at the first missing hop, no error.

🔸 The ? only protects the bracket it sits in front of. triggerBody()?['missing']['x'] fails with property 'x' cannot be selected, and triggerBody()?['nested']['zz'] fails with property 'zz' doesn't exist, available properties are 'a'.

2. Arrays: ?[0] works the same way

🔸 triggerBody()?['arr']?[0] returns 1.

🔸 triggerBody()?['arr']?[10] returns null. Without the operator, triggerBody()?['arr'][10] fails with array index '10' is outside bounds (0, 2) of array.

3. Property missing vs. property null

🔸 triggerBody()['nullProp'] succeeds and returns null: the property exists, its value is null, no ? needed.

🔸 triggerBody()['missing'] fails: property 'missing' doesn't exist, available properties are 'name, nested, nullProp, arr'. Only the ? turns this into null.

🔸 Once you use ?, both cases look identical: equals(triggerBody()?['missing'], null) is true, equals(triggerBody()?['nullProp'], triggerBody()?['missing']) is true, empty(triggerBody()?['missing']) is true.

4. What the error looks like without ?

🔸 The action fails with status Failed, error code InvalidTemplate, and the message names the available properties:

1
2
3
Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0':
'The template language expression 'triggerBody()['missing']' cannot be evaluated because property 'missing'
doesn't exist, available properties are 'name, nested, nullProp, arr'.'

5. What ? does not protect against

🔸 A wrong type. triggerBody()?['name']?['x'] on the string Alice fails with Property selection is not supported on values of type 'String'. The operator handles missing and null, not a value that is a string where you expected an object.

🎉 Result

Your flows keep running even when incoming data is inconsistent, returning null instead of throwing errors, far more robust and easier to maintain.

🌟 Key Advantages

🔸 Prevents runtime errors from missing properties

🔸 Returns a predictable null you can handle explicitly

🔸 Minimal effort, just one character per reference

🎥 Video Tutorial

🛠️ FAQ

1. What is the safe navigation operator (?) in Power Automate?

The safe navigation operator (?) prevents runtime errors when accessing properties that may not exist on an object or array element, returning null instead of throwing an error.

2. When should I use item()?['property'] instead of item()['property']?

Use item()?['property'] whenever a property might be missing or undefined, so your flow doesn’t fail and handles missing values gracefully.

3. Will using the safe navigation operator affect performance?

No. It has minimal performance impact and greatly improves the stability of your flows by avoiding unnecessary errors.

4. Does ? also work on array indexes?

Yes. body('x')?['arr']?[10] returns null when the index does not exist; body('x')?['arr'][10] fails with array index '10' is outside bounds.

5. Is a missing property the same as a null property?

Without ? no: a property that exists with value null returns null, a property that does not exist fails the action with property 'x' doesn't exist. With ? both return null and equals(..., null) is true for both.

🔸 #PowerPlatformTip 33: ‘Coalesce’ - pair ? with coalesce() to also supply a fallback value instead of null.

🔸 #PowerPlatformTip 104: ‘Efficient JSON Handling’ - build a null-tolerant Parse JSON schema for the same inconsistent data.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.