azure-logic-apps

How to handle null value in logic app condition module


I have a logic app where i use a condition expression on to two variables, displayName and accountName.

Sometimes a variable will not exist. which will cause this error:

InvalidTemplate
Unable to process template language expressions for action 'Condition' at line '0' and column '0': 'The template language function 'contains' expects its first argument 'collection' to be a dictionary (object), an array or a string. The provided value is of type 'Null'.'.

How do i handle this error? I want the condition to treat the null value as if the variable is a empty string

enter image description here

Is it possible to write a expression thats like iff(accountName is empty(), '', accountname)?


Solution

  • You can do so by using coalesce() function.

    I am using below given expressions to achieve this.

    coalesce(variables('accountName'),'')
    coalesce(variables('displayName'),'')
    

    enter image description here

    This works if one variable is not exist. Here I am only passing the value of account name but not display name.

    enter image description here