Expression returned null or empty – The expression returned an unexpected null or empty result.

Loading

In Power Automate, expressions process data dynamically. However, sometimes an expression returns null or an empty value, causing the flow to fail with the following error:

“Expression returned null or empty – The expression returned an unexpected null or empty result.”

This error occurs when:

  • The data source does not return a value (e.g., SharePoint list lookup finds no match).
  • A variable is uninitialized or has no value.
  • A field is missing from JSON data.
  • An array or object is empty and an index lookup fails.

2. Common Causes of Null or Empty Expression Errors

CauseDescriptionExample
Missing or Null Field in JSONThe expected field does not exist in the data.body('Get_item')?['Title'] returns null.
Empty or Uninitialized VariableThe variable was never set before being used.variables('myVar') is empty.
Empty Array AccessTrying to retrieve data from an empty list.first(body('Get_items')?['value']) fails if empty.
Null Lookup ResultLookup action (e.g., SharePoint Get Item) found no match.body('Get_item')?['ID'] returns null.
Incorrect Array IndexingAccessing an index that does not exist.body('Get_items')?['value'][0] when the array is empty.

3. Step-by-Step Troubleshooting Guide

Step 1: Identify Where the Null or Empty Value Occurs

  1. Go to Power Automate (https://flow.microsoft.com).
  2. Navigate to My Flows and open the flow with the error.
  3. Click Run History and locate the failed run.
  4. Expand the failed action and look at the expression that caused the error.

Check if the value is null or empty in the output section.
✔ Look for messages like:

  • "Value cannot be null"
  • "The expression expects a value but received null"

Step 2: Check for Missing or Null JSON Fields

If the expression references a missing field, it will return null.

Solution: Use the coalesce() function to provide a default value.

Example Fix:

coalesce(body('Get_item')?['Title'], 'No Title Found')

This returns “No Title Found” instead of failing when Title is missing.


Step 3: Ensure Variables Are Initialized

If a variable was never assigned a value, accessing it results in an empty value.

Solution:

  1. Before using a variable, initialize it with a default value.
  2. Use coalesce() to check if it’s empty.

Example Fix:

coalesce(variables('myVar'), 'Default Value')

This ensures myVar always has a value.


Step 4: Handle Empty Arrays Before Accessing Elements

If an array is empty, trying to retrieve the first item will fail.

Solution:

  1. Use length() to check if the array has items before accessing them.
  2. Provide a default value if empty.

Example Fix:

if(length(body('Get_items')?['value']) > 0, first(body('Get_items')?['value']), 'No Data')

This checks if the array has data before trying to access the first item.


Step 5: Use Safe Navigation for JSON Fields

If a field is missing, direct access fails. Instead, use ?[] notation.

Solution:
Example Fix:

body('Get_item')?['Title']

This prevents the flow from failing if Title is missing.


Step 6: Prevent Null Values in Lookups

When using “Get Item” or “Get Rows”, if no record is found, the response will be null.

Solution:

  1. Check if the lookup action returned data before using it.
  2. Use coalesce() to provide a default value.

Example Fix:

coalesce(body('Get_item')?['Title'], 'No Record Found')

This prevents the error when a lookup fails.


Step 7: Validate Inputs Before Using Expressions

Ensure input data is not null or empty before applying transformations.

Solution:
Example Fix:

if(empty(triggerOutputs()?['body']['email']), 'No Email Provided', triggerOutputs()?['body']['email'])

This prevents errors when the email field is missing.

Leave a Reply

Your email address will not be published. Required fields are marked *