Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Getting errors with null fields


View products that this article applies to.

Symptoms

In Microsoft Power Automate, when you create a flow, here is what could happen with null field that cause trouble:

  1. You may be expecting wrong behavior when perform an action with null field.
  2. If you are not handling null fields correctly, you may be expecting runtime errors like:
    • InvalidTemplate. Unable to process template language expressions. The provided value is of type 'Null'.

[Asset 4536658]

↑ Back to the top


Cause

  1. If a flow runs with a null field, it will cause:
    • Wrong behavior: flow action's input is receiving null field, when it expects a different value.
  2. Use expression towards null fields. It will cause:
    • Runtime error: expression expects its parameter to be a string, an object or an array but receives null. 

↑ Back to the top


Flow error resolution

You can set up a condition check for null field. Here is the steps to create a condition check for null.

1. Add a new condition action.

[Asset 4536170]

2. Choose dynamic content output (e.g. user email) you want to check.

[Asset 4536498]

3. Set the operation to be (e.g.) "is not equal to".

4. Put the value field as the expression value "null".

[Asset 4536505]

↑ Back to the top


Runtime error resolution

You can also use coalesce function to provide default values when a value is null. For example, using coalesce(trigger().outputs, '') will default to empty string when trigger().outputs is null.

[Asset 4536499]

Note: If you are still getting a runtime error, it may be caused by reference null properties in an object. You should use the question mark operator "?". For example, to handle null outputs from a trigger, you can use this expression:

@coalesce(trigger().outputs?.body?.<someProperty>, '<property-default-value>').

See Coalesce functionOperators for more information.

↑ Back to the top


Keywords: condition, nullreferenceexception

↑ Back to the top

Article Info
Article ID : 4535432
Revision : 33
Created on : 12/20/2019
Published on : 12/20/2019
Exists online : False
Views : 102