cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ryanb888
Regular Visitor

Flow condition using date not working when date is null

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.'.

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Community Champion
Community Champion

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

View solution in original post

6 REPLIES 6
DamoBird365
Community Champion
Community Champion

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

View solution in original post

Pstork1
Dual Super User III
Dual Super User III

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'))


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
DamoBird365
Community Champion
Community Champion

Nice one @Pstork1 !  Thank you for that. 👍

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?

HI @ryanb888 

 

Your example is correct.

 

if(empty(triggerBody()?['efa_resolvedon']),'',formatDateTime(triggerBody()?['efa_resolvedon'],'yyyy/MM/dd')) 

 

Damien

Pstork1
Dual Super User III
Dual Super User III

Sure,  the code when using Coalesce would be as follows:

formatDateTime(coalesce(triggerBody()?['efa_resolvedon'],'2021-01-01'),'yyyy/MM/dd')


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (5,446)