Today, we will learn how to check an empty value on a variable under Power Automate.
I had a requirement where I need to push my Lead record data from Dynamics CRM to another application.
To fulfill this requirement, I thought of going with power automate. Which would trigger whenever a record is created under the Lead entity and then push the data to another application.
Here I have a field Due Date which is an optional field on a form. So now it is a user who chooses to enter data or not.
I have a child flow where I need to pass the data of Due Data as well. Below is the JSON schema for Child Flow. We can see that the due date is of string type, therefore if we pass null value it would throw us an error: Invalid type. Expected String but got Null
To handle this scenario, we can use an empty expression:
syntax: if (empty(duedate), ”, duedate)
expression used to check field(duedate) was empty:
if (empty(string(triggerOutputs() ? ['body/duedate'])), '', triggerOutputs() ? [' body/duedate'])
How the expression work is it checks whether the field is empty or not, which means if the value is null or empty then it returns true which will pass ” not null. This is accepted as a string. Else, if the field contains a value then it would pass the field value.
Hope this help!