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:
Overview of the rule:
The trigger of the rule can be changed to a Scheduled one, with a cron job of running once per day.
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 more
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:
Important: Our regex must be enclosed to (), otherwise it will stop on the first two digits.
And finally the action of the rule, which could be anything. In our example an email to the administrator group.
Let me know your thoughts on this!
Alex
Alex Koxaras _Relational_
Atlassian Solution Architect
Relational
Athens, Greece
1,360 accepted answers
2 comments