top of page

Tip: Handle Null date field in Power Automate


A neon sign displaying the words Top Tips
Top Tip


Hey all,


Just a quick one from me today, I will show you how to Handle Null date field in Power Automate.


I was working on something recently where the flow failed because, a non-mandatory date field had not been filled in on a Model Driven app.


I handled it below:


if(equals(first(outputs('List_rows')?['body/value'])?['[date_field'], null), '', formatdatetime(first(outputs('List_rows')?['body/value'])?['date_field'],'dd/MM/yyyy'))


Let's break it down.


first(outputs('List_rows')?['body/value'])?['[date_field']


Gets the first date_field (replace with your own logical name field) from the step called "List Rows". This stops the step falling into an apply to each. You can find out more on this from my First blog post.


Next we wrap that in the if and equals


if(equals(first(outputs('List_rows')?['body/value'])?['[date_field'], null), '',


This means that, if the date_field comes back as null, replace it with an empty string - '' (2 single quote marks).


After the comma, we then need the value, if the if statement doesn't bring back a null. This is this part:


formatdatetime(first(outputs('List_rows')?['body/value'])?['date_field'],'dd/MM/yyyy'))


Where we are formatting the date_field to be dd/MM/yyyy i.e. 30/07/2024.


Put that all together and you get:


if(equals(first(outputs('List_rows')?['body/value'])?['[date_field'], null), '', formatdatetime(first(outputs('List_rows')?['body/value'])?['date_field'],'dd/MM/yyyy'))


Thanks for reading, hope you have a good day.


Jon


105 views0 comments

Comments


bottom of page