Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Automation compare Variable to date

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

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

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 Jan 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

Suggest an answer

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

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you