Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,362,086
Community Members
 
Community Events
168
Community Groups

Jira automation and Insight: Acquiring an insight date attribute and compare it with a Jira date

Today I came across a question in the Atlassian Community about insight and a way to alert a user if an insight object date was close to “today”. At first I thought that it would be quite easy to acquire the date of an Insight Object  and compare it to a another date field within a project. To be fair, acquiring the date was quite easy. But comparing it was another different thing!

The need (and I quote the person who asked the question): “I want Jira to send me an e-mail when a date in an insight object is reached,... well, some days befor it'S reached.”

The plan: Create an insight object field, set it up, place it on appropriate screen and create the automation rule.

The problem: Insight object date attributes are not of the same format like these of Jira. And using Groovy’s “.format(<pattern>)” is not a solution, since the date acquired is treated like a string, rather than a date.

The solution: The solution I’ve came up with, was to use Jira smart values and transform the text into a date format, by using a Regular Expression.

The above solution seemed quite easy in mind, but alas, since me and Regex Expressions are strangers to each other, it was quite cumbersome. However after struggling for an hour or so, I had the complete solution which I present here:

  1. First, create a custom Insight object field. In my case I named it CDI.
  2. Place the above field on the appropriate screens of your project
  3. Setup CDI field but its all up to how you have set up your objects really (in my case Computers was an object one level below Hardware object):
    field configurat.png
  4. Create and adjust the following rule

 

Rule

Overview of the rule:

  1. myRule001.png

The trigger of the rule can be changed to a Scheduled one, with a cron job of running once per day.

Create a Variable

Inside this variable we will store the insight object's value. The reason for using a variable to store Insight Object Date attribute, is because any smart value property would not work with the CDI custom field (being an insight object). So after trial and error I found out that storing the date into a new variable, gave me the opportunity to develop the rule further moremyRule002.png

Compare Dates

All the magic was this line of code with the @#$@#$@ regex. Blessed is Google and those who know how to use it. To those who are common mortal people like myself, this was a bit tricky to find. 😊

{{jiraDate.match("((\d{2})\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\/(\d{2}))$").toDate.plusDays(7)}}

Let’s breakdown the above regular expression. Keep in mind that we are looking for a date with the format of “dd/MMM/yy”, e.g. : 18/Aug/22:

  • jiraDate -> get the variable which we created previously
  • .match("”) -> we use the match property to find the date, exactly how is formatted in insight, meaning dd/MMM/yy
  • (\d{2} )-> we are looking for two digits
  • \/ -> We are looking for a forward slash “/”. The backward slash is the escape character which let us use the forward slash
  • (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) -> We search for any word included inside the parenthesis. In our case we are searching for the month written with three letters
  • \/ -> Again the
  • (d{2}))$ -> Again we are searching for two digits
  • .toDate -> and we convert the above finding to a date
  • .plusDays(7)}} -> and we add to the above date 7 days

Important: Our regex must be enclosed to (), otherwise it will stop on the first two digits.

myRule003.png

Send email

And finally the action of the rule, which could be anything. In our example an email to the administrator group.myRule004.png

 

Let me know your thoughts on this!

Alex

 

 

2 comments

Fabian Lim Community Leader Aug 21, 2022

Great article! 

Like Alex Koxaras likes this

Thank you @Alex Koxaras for sharing this article.  The steps are very clear to follow, I'll try it out when I'm back from a short needed vacation!!!

Like Alex Koxaras likes this

Comment

Log in or Sign up to comment
TAGS

Atlassian Community Events