There are times in which we need to check for certain conditions in order to achieve the desired outcome of a workflow. Most of the time, we have a value to check a condition against, but there are other times in which we just need to check whether or not a field is empty. Coming from SharePoint Designer workflows, that was an easy task to achieve, but with Microsoft Flow, a different approach is required.
The best way to check for null value is using the Coalesce function. The Coalesce function “returns the first non-null object in the arguments passed in. Note: an empty string is not null. For example, if parameters 1 and 2 are not defined, this function returns fallback”. The function is structured as follows:
Lately, I’ve been spending a lot of time in the Microsoft Flow Community Boards to learn more how the community is using Flow and there was a post from a user wanting to check a condition against an empty string from a Microsoft Forms field. Based on his requirements, I created a Form with a date field in it, and set a Flow to check whether or not this date field is empty. I was able to achieve this with the Flow detailed below.
I called my Flow “Get Form Booking Date” and it’s triggered when a new response is submitted. In the trigger step, I set the Form Id to the name of the Form.
In the next step, I called the Get response details action, which will retrieve all the responses from the Form in the previous step. Since there might be multiple responses, Flow will add an Apply to each step. In here, I populated the “Select an output from previous steps” field with the List of response notifications. See screenshots below.
The next step is the Condition. This is where the Flow will check for the null value in the specified field, which in my case is the Booking Date field. In the Condition step, I clicked on the “Choose a value” field and then selected the Booking Date field from the Dynamic content window.
This is the condition in basic mode after selecting the Booking Date field:
Once the field is selected, I switched the condition to “Edit in advanced mode” so I can enter the coalesce function. Note: whenever a condition is edited on advanced mode, the function needs to be preceded by a @. This is the complete function in the Condition step:
This is the breakdown of all the components in the function from inside out:
- The Booking Date field. In advanced mode, this field is presented as a GUID instead of its actual name
- The body from the Get response details step
- The coalesce function with the objects to check for null
- The equals function with the object to compare to Object 1. Object 1 is the section within the coalesce function above. Object 2 is highlighted below.
Once the condition is fully set, the Flow will follow with a Yes or No step, which I followed with a simple email, but you can follow it with any other actions based on your requirements.