I have a flow where the for a date column i am formatting this and adding it to an excel file.
When the date is null the flow fails as a string rather than null.
Any ideas on how to resolve this? below is the error message:
Unable to process template language expressions in action 'Formatted_case_resolved_date' inputs at line '1' and column '3097': 'The template language function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#formatdatetime for usage details.'.
Sure, the code when using Coalesce would be as follows:
formatDateTime(coalesce(triggerBody()?['efa_resolvedon'],'2021-01-01'),'yyyy/MM/dd')
HI @ryanb888
Your example is correct.
if(empty(triggerBody()?['efa_resolvedon']),'',formatDateTime(triggerBody()?['efa_resolvedon'],'yyyy/MM/dd'))
Damien
thanks for your reply, my existing code is formatDateTime(triggerBody()?['efa_resolvedon'],'yyyy/MM/dd'))
in your code provided would you be able to incorporate the trigger body? or is your code an alternative for formatting the data where trigger body is not required?
Nice one @Pstork1 ! Thank you for that. 👍
Empty() is for determining Empty strings. The better choice here would be to use Coalesce(). Coalesce process the parameters from left to right and accepts the first one that isn't null. So you can supply your date as the first entry and a default date as the second. If the first entry is null the second will be used. Something like this
formatdatetime(colalesce(DateTimeField,'1900-01-01'))
Hi @ryanb888
Without seeing the action you are using, you could use a compose with an if expression. For example:
if(empty(dynamicdatevalue),'',formatdatetime(etcetc,'yyyy-MM-dd'))
This would check for your date value being empty, and if so output '', otherwise it would use the formatdatetime.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
P.S. take a look at my new blog here
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional