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
Cause | Description | Example |
---|---|---|
Missing or Null Field in JSON | The expected field does not exist in the data. | body('Get_item')?['Title'] returns null . |
Empty or Uninitialized Variable | The variable was never set before being used. | variables('myVar') is empty. |
Empty Array Access | Trying to retrieve data from an empty list. | first(body('Get_items')?['value']) fails if empty. |
Null Lookup Result | Lookup action (e.g., SharePoint Get Item) found no match. | body('Get_item')?['ID'] returns null . |
Incorrect Array Indexing | Accessing 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
- Go to Power Automate (https://flow.microsoft.com).
- Navigate to My Flows and open the flow with the error.
- Click Run History and locate the failed run.
- 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:
- Before using a variable, initialize it with a default value.
- 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:
- Use
length()
to check if the array has items before accessing them. - 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:
- Check if the lookup action returned data before using it.
- 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.