How to do a 'null' check in 'if' condition action of Azure Logic App How to do a 'null' check in 'if' condition action of Azure Logic App azure azure

How to do a 'null' check in 'if' condition action of Azure Logic App


You can now do:

 @equals(triggerBody()['jsonObj']?['someProperty'], null)

It's valid and can be saved but if you try to switch to Basic mode you'll get an error. Can still save though.


I did not found a real way to directly test against null or undefined but the following workaround should work when choosing a sufficient 'random' string as fallback for the coalesce

..."propExists": "@equals(coalesce(triggerBody()?.prop, 'Fallback42'), 'Fallback42')"...

For example the following Logic App would echo back the property prop and whether it was actually specified or not

{    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",    "actions": {        "Response": {            "inputs": {                "body": {                    "propNull": "@equals(coalesce(triggerBody()?.prop, 'undefined'), 'undefined')",                    "prop": "@triggerBody()?.prop"                },                "statusCode": 200            },            "runAfter": {},            "type": "Response"        }    },    "contentVersion": "1.0.0.0",    "outputs": {},    "parameters": {},    "triggers": {        "request": {            "inputs": {                "schema": {}            },            "kind": "Http",            "type": "Request"        }    }}

so that a request with

{    "prop": "test"}

results in

{  "prop": "test",  "propNull": false}

whereas a request with

{    "propOther": "test"}

results in

{  "prop": null,  "propNull": true}


Another option is to do a string concatenation in the designer and check for a value > '' (a space.)

For example below I am iterating over a set of agents where their email is potentially NULL, joining a null string to an empty string results in an empty string.

This has the advantage of working in both the designer and code view.

@concat('', items('iterateAgents')?['email'])

This end up looking like the following in the code view

                "expression": {                    "and": [                        {                            "greater": [                                "@concat('', items('iterateAgents')?['email'])",                                "  "                            ]                        }                    ]                },