07 December 2020

How do I - Check if a field is empty in PowerAutomate?

In PowerAutomate there is a empty() function that can be used, but it doesn't work the way you think.  Take the following example from a mentee question:


In this Set variable action, we are trying to set varFundDateExists to true or false depending on if there's a value in the "RD Funded Expiration Date" control.  The attempt used here is:

@not(empty(items()?['RD_x0020_Funded_x0020_Expiration_x0020_Date']))

Unfortunately, the empty() function doesn't work as expected.  How do we solve this problem then?

I've seen this suggested solution on powerusers.microsoft.com where doing a date calculation allows you to determine if the target date field is blank:

Value(Today()) - Value(items()?['RD_x0020_Funded_x0020_Expiration_x0020_Date']) = Value(Today())

The theory is that if there is a date in the target field, the value won't match today's date and return false.  The exception to this is when the target field contains today's date in which case it will return true.

The best way to do the check is as follows:

Equals(['RD_x0020_Funded_x0020_Expiration_x0020_Date'], null)


Happy coding...
C


No comments:

Post a Comment

Comments are moderated only for the purpose of keeping pesky spammers at bay.

Microsoft Authentication Library (MSAL) Overview

The Microsoft Authentication Library (MSAL) is a powerful library designed to simplify the authentication process for applications that conn...