Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation compare Variable to date

Peter Weir January 17, 2021

I am trying to get an automation to work.

I have set a variable and used Reg ex to get the data from the description.

{{issue.description.match("date created: ?(.*)")}}

What I want to do is an Advanced Compare condition to say if by variable is after today.

I can not get it to work. Im guessing that my date formats are not correct but don't know where to look.

 

Can anyone help

2 answers

2 votes
Peter Weir January 18, 2021

So I have got it working so just in case anyone has a similar requirement

In the Description of the ticket I had 

date created: 2021-01-17

In Automation I create a variable called createddate as follows

{{issue.description.match("date created: ?(.*)").toDate.jiraDate}}

 I also created a variable called datetoday

{{now.jiraDate}}

 I can then do and Advance compare condition that says

{{createddate}} equals {{date today}}

 

Granted in the request was to do greater but I realised that in my use case I actually needed equal. I have not tested but I assume I could change it to be greater than and it should work.

 

Thanks for the help however.

bmccoy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 19, 2021

Hi Peter,

Glad to hear you got it working.  I think if you want to do a greater than comparison, you will need to use the date functions for the comparison and check for true/false values

The advanced condition will look a bit like

{{issue.description.match("date created: ?(.*)").toDate.isAfter(now)}}

 equals

true

 Cheers,
Brydie

Yatish Madhav
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2023

Thanks @Peter Weir - this has help me. I have upvoted as answer. Thank you

0 votes
Darryl Lee
Community Champion
January 18, 2021

Can you provide a sample of what the issue description might look like? It's hard to debug regexes without the source data.

I think the problem is that question mark before the (.*). Question marks usually follow + or * quantifiers to designate that they should be "non-greedy". But assuming "date created:" is on a line by itself, you don't need to worry about any of that. Assuming your issue description looks something like this:

Description of issue

date created: 18/Jan/2021

other field: foo

another field: bar

Then this would work:

{{issue.description.match("date created: (.+)")}}

So, I tested this by creating a rule with a Manual trigger that can only by run by Administrators/Site Admins, etc.

The rule has one action: Log action where you would put the smart value you're testing.

Then you go to a test issue, click on Automation -> Rule Execution, and test it out. You'll want to watch/reload the log and keep tweaking the regex until you get what you're looking for.

And yes, you will probably need to worry about Date formats. You can read all about that here: https://support.atlassian.com/jira-software-cloud/docs/smart-values-date-and-time-functions/

The same testing process would work to get your dates formatted in a way that they can be accepted by an actual date field.

Also, if your regex becomes more complex, I recently used this online tester which lets you interactively try out regexes, which is really handy:

https://www.freeformatter.com/java-regex-tester.html

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events