6 min readRishi

Eliminating Null Reference Errors in Power Automate Flows

In this series: Power Automate gotchas

Eliminating Null Reference Errors in Power Automate Flows

"The template language expression cannot be evaluated because property 'fieldname' doesn't exist."

The flow worked on Friday. Monday's row has no company. The expression triggerOutputs()['body']['company'] throws, the run fails, and nothing downstream ran. That message is the usual runtime failure in Power Automate. It almost always means the same thing: a field that was optional on the source record is missing from the JSON, and the expression treated a missing property like a value.

When a Dataverse, SharePoint, or API response does not include a field — because it is null, empty, or optional — the property is absent. It is not null sitting in the object waiting for equals(..., null). The path does not exist. Optional ? access returns empty. Bare ['company'] explodes.

Safe access, then a default, then a branch

Three tools, in that order.

The ? in property access paths is the one that stops the throw:

triggerOutputs()['body']['company']           // throws if body or company is missing
triggerOutputs()?['body']?['company']         // empty if either is missing

Always use ?['property'] instead of ['property'] or .property notation. .property looks friendly in the designer and still throws on a missing object.

coalesce() returns the first non-null value from a list. Use it when a missing field should become a real substitute:

@coalesce(triggerOutputs()?['body/company'], 'No Company')

empty() plus if() is for when you need a branch, not a string to splice into an email:

@if(
  empty(triggerOutputs()?['body/phone']),
  'N/A',
  triggerOutputs()?['body/phone']
)

For nested objects that can vanish at any level, keep ? on every hop and wrap the whole path:

@coalesce(
  triggerOutputs()?['body']?['primarycontactid']?['fullname'],
  'Unknown Contact'
)

body/company (slash) and body']?['company'] (bracket hops) both work on a flat trigger body. Nested objects and arrays are safer as hops. Pick one shape per field and keep it.

Dates have extra empty shapes — "", 0001-01-01, Excel serials — covered in null and blank dates. coalesce alone will not catch a sentinel timestamp.

The payload that looks like production until it does not

A Dataverse trigger with Select columns set to name,emailaddress1 will not contain telephone1, even when the record has a phone number. An omitted column is absent from the payload, which is the same shape as a null. Select columns is not just a performance tweak. Only select columns the flow reads, and wrap every one of them. The same trim exists on List rows; it is a payload cut, not the trigger filter that decides whether the flow starts.

Lookup fields in Dataverse are objects, not simple values. A null lookup means the entire object is missing. _ownerid_value is the GUID when it is present. When it is not, the key is gone:

coalesce(triggerOutputs()?['body/_ownerid_value'], '')

Do not walk _ownerid_value and then assume _ownerid_value@OData.Community.Display.V1.FormattedValue exists. The formatted label is a sibling that is also optional.

Array access fails the same way on an empty List rows:

first(body('List_rows'))                                          // throws or nonsense on empty
if(empty(body('List_rows')?['value']), null, first(body('List_rows')?['value']))
first(coalesce(body('List_rows')?['value'], json('[]')))

The third form is the one to paste. first of an empty array is still a failure. first of [] you supplied is empty, and coalesce can sit around it.

HTTP bodies change shape with status. Guard the status before the path:

@if(
  equals(outputs('HTTP')?['statusCode'], 200),
  body('HTTP')?['data']?['result'],
  'API Error'
)

A Compose that reads body('HTTP')['data']['result'] on a 404 is the Monday morning failure, even if you have a Condition on status two steps later. Expressions on a card run when the card runs. Put the path behind the Condition, or use ? and accept empty.

Fail the run on purpose, or skip it

Required fields should not become 'Unknown'. If an order cannot post without an account, terminate. A Condition at the top that names what is missing is cheaper to debug than a downstream connector error:

@and(
  not(empty(triggerOutputs()?['body/name'])),
  not(empty(triggerOutputs()?['body/email'])),
  greater(length(coalesce(triggerOutputs()?['body/items'], json('[]'))), 0)
)

If validation fails, Terminate with a message that includes the record id and the field. Pair that with a scope / run-after if a later action can still throw.

When missing data means "do nothing," a trigger condition is cheaper than Compose + Condition + Terminate:

@not(empty(triggerOutputs()?['body/emailaddress1']))

A false trigger condition does not start a run and does not write run history. That is the point, and it is why a wrong condition looks like a dead flow. How to inspect skipped checks is in trigger conditions.

Normalize once. Compose CustomerName as @coalesce(triggerOutputs()?['body/fullname'], 'Unknown') and reference outputs('CustomerName') after that. Repeating a twelve-hop path is how one hop loses its ?.

For HTTP-triggered flows, define a JSON schema on the trigger. Power Automate rejects payloads that miss required properties before your expressions run. Optional properties still need ? when they arrive as absent.

When a default is the wrong fix

Do not coalesce a money field to 0. A missing amount is not a free order. Terminate.

Do not coalesce an email to a shared mailbox "so the send action succeeds." You will send the customer's data to the wrong place. Skip the send.

Do not wrap every expression in coalesce(..., '') and then concatenate those blanks into Dataverse. You will write empty strings over nulls and change the meaning of "field was never set."

empty('') is true. empty(' ') is false. Trim if the source is a form people space-bar through.

Hardening checklist

  1. Open a successful run and a failed run. Diff the trigger JSON. The missing key is the name you must wrap, not the display name on the form.
  2. Search the flow for [' without a ? immediately before it. Those are the throws.
  3. List every Select columns / $select. Confirm each later expression's field is in that list.
  4. For List rows, confirm you use body('…')?['value'] and never first without an empty guard.
  5. Put required-field checks before the first connector that writes. Optional fields get coalesce or a skip, not a throw.
  6. Reproduce with a record that has the optional lookup cleared, the optional phone cleared, and Select columns left as they are in production.

?[] on every hop, coalesce on optional values you are willing to substitute, and an early check on values you are not: that combination is what stops the property-does-not-exist failure. The remaining misses are almost always a column you did not select, or a default you should not have invented.

Keep reading

Newsletter

New posts, straight to your inbox

One email when a new post goes up. Double opt-in, unsubscribe anytime. Not a daily digest.

Comments

  • No comments yet. Be the first.