cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
414--365
Frequent Visitor

Check condition for date greater than current year

Hello,

 

I'm trying to set up a check condition to compare a date field on a Dynamics record, to see if that date is greater than or outside of the current year. I haven't seen any posts quite like this, many reviewing comparing a date to the current date or a date with an added duration (10 days). 

 

date greater than current year.jpg

This kind of comparison can be done OOB in an Advanced Find in Dynamics, so I'm thinking a check condition can be created for a variable time frame (current year). Any insights will be greatly appreciated!

 

Best,

414-365

2 ACCEPTED SOLUTIONS

Accepted Solutions
GeorgiosG
Super User
Super User

Sorry my mistake, ticks is not necessary when we just talk about the years. You have to add it with the expression also the data verse variable:

 

GeorgiosG_0-1650556838417.png

 

For the Dataverse Variable, instead of utcNow() insert via the Dynamic Data Tab your Variable from Dataverse.

You can immediately work with the data verse Variable, if you facing issues with the format you can store it in an integer Variable right before.

Happy to help.
If I have answered your question, please mark your post as Solved.

View solution in original post

I wasn't seeing errors due to blank field values, but that is helpful! What I ended up needing to do was take my date column and initializing it as a string value formatted using formateDateTime:

date greater than current year 5.jpg

Then comparing that with formatDateTime(utcNow(),'yyyy') worked without any errors. Thanks again for all of your help!

View solution in original post

9 REPLIES 9
GeorgiosG
Super User
Super User

So you search for the current year ?

You can try that expression to get the current year: 

 

formatDateTime(utcNow(),'yyyy')

 

If you want to compare the year of your Dataverse Date and current year you can compare ticks(formatDateTime(DataverseRecord,'yyyy')) is greater than ticks(formatDateTime(utcNow(),'yyyy')).

Happy to help.
If I have answered your question, please mark your post as Solved.
GeorgiosG
Super User
Super User

 

 

Happy to help.
If I have answered your question, please mark your post as Solved.

Thank you for the help! Do I need to take the DataverseRecord and establish the variable prior to the comparison? Below is what I attempted but am unable to insert the DataverseRecord:

date greater than current year 2.jpg

GeorgiosG
Super User
Super User

Sorry my mistake, ticks is not necessary when we just talk about the years. You have to add it with the expression also the data verse variable:

 

GeorgiosG_0-1650556838417.png

 

For the Dataverse Variable, instead of utcNow() insert via the Dynamic Data Tab your Variable from Dataverse.

You can immediately work with the data verse Variable, if you facing issues with the format you can store it in an integer Variable right before.

Happy to help.
If I have answered your question, please mark your post as Solved.

Ah that makes sense. Here's what I'm using for the check:

formatedatetime(triggerOutputs()?['body/DataverseVariable'],'yyyy')

date greater than current year 3.jpg
 
In testing I'm receiving the below error:
Error - Action 'Check_if_the_datAverse_variable_is_in_the_next_year' failed
Error Details - Unable to process template language expressions for action 'Check_if_the_dataverse_variable_is_in_the_next_year' at line '0' and column '0': 'The template function 'formatedatetime' is not defined or not valid.'.
 
Would that indicate I need to store the variable as an integer as you noted?
GeorgiosG
Super User
Super User

Are you using DataverseVariable or did you just replaced it with DataverseVariable?

 

You need to select your special Date Field 

looks like: 

formatDateTime(outputs('Get_a_row_by_ID')?['body/@odata']?['Date'],'yyyy')

 

1. Click into the the Condition 

2. Select Expression in the pop up

3. Type in formatDateTime(,'yyyy')

4. Insert your cursor right before the comma formatDateTime(Here,'yyyy')

5. Click on Dynamic Data Tab and search for your field and click it

 

 

GeorgiosG_0-1650558347580.png

 

Happy to help.
If I have answered your question, please mark your post as Solved.

I'm replacing the column name with DataverseVariable. I attempted to follow your steps and am now getting a different error. Previously I was only using a Trigger to pull in the column, where I've now added the "Get a row by ID" step:date greater than current year 4.jpg

 

This is the full expression with the column replaced by Database_Variable:

formatDateTime(outputs('Get_a_row_by_ID')?['body/database_variable']?['Date'],'yyyy')
 
The error details now state:
Unable to process template language expressions for action 'Check_if_the_database_variable_is_in_the_next_year' at line '0' and column '0': 'The template language expression 'formatDateTime(outputs('Get_a_row_by_ID')?['body/database_variable']?['Date'],'yyyy')' cannot be evaluated because property 'Date' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.
 
I will check the provided link but the column I'm referencing is a Date Only data type column. I appreciate your help with this!
GeorgiosG
Super User
Super User

I tested it by myself and was facing the same error. After some investigation I found that the data (Date) sometimes is empty because this was not a mandatory field. Maybe some entries don't have a value for your date field as well.

You can check this also in you condition if the value is empty, then this entry will be skipped.

You can use empty()

 

empty(items('Apply_to_each')?['startdate']) is equal to false
 
Tip: Using the action Compose in front of your condition, let you see in the run history how the data looks like you want to compare.
 
GeorgiosG_1-1650571750448.png

 


 

Happy to help.
If I have answered your question, please mark your post as Solved.

I wasn't seeing errors due to blank field values, but that is helpful! What I ended up needing to do was take my date column and initializing it as a string value formatted using formateDateTime:

date greater than current year 5.jpg

Then comparing that with formatDateTime(utcNow(),'yyyy') worked without any errors. Thanks again for all of your help!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (1,868)