Need help on recurring tasks and groovy scripts and auto-transition?

Warren McInnes
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.
March 3, 2013

I'm trying to develop a method of using a recurring issue type in Jira, I have built a simple workflow in Jira and associated it to the issue type "Recurring task"

The workflow is simple:

Open -> Active <-> Inactive -> Closed(permanetly)

I also have 3 customfields i would like to use:

1. Frequency - Select list - ("Daily(1d)", "Weekly(7d)", "Biweekly(14d)", "Monthly(30d)", "Quarterly(90d)", "Annually(365d)")

2. Lead time reqirement - Select list - ("None", "1 day", "2 days", "3 days", "7 days", "14 days", "30 days", "60 days", "90 days")

3. Calendar Due date - Date picker - Default value of CurrentDate

Firstly I require some method to do an "Auto-Transition" (From in-active -> active, when a condition is met:

Condition: when (due date + frequency) = new due date

So basically it must have the inital date when created + the frequency date(eg,1d-365d) then that should then become the new date and basically replace the initial due date <- this should only be relevant on in the in-active status

So what I would like out of this is that once a new dute has been automatically transitions from in-active to active only.

For active to in-active that must be set manually on the task is completed.

Can anyone give advice or guidence?

14 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
Henning Tietgens
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.
March 11, 2013

Regarding your question in the comment on having a transition available after some days, you could try this as a Script Runner scripted condition:

import com.atlassian.jira.component.ComponentAccessor

def changedDate
int numDays = 3
def now = new Date()

def changeItems = ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, 'status')
if (changeItems.size()&gt;0) {
    changedDate = changeItems.sort{it.getCreated()}.last().getCreated()
} else {
    changedDate = issue.getCreated()
}

return (changedDate + numDays &lt; now)

This tests if the last change of the status (the last transition) plus a number of days (here 3) is before the current date and time. If this is true, the condition evaluates to true and the transition is available (if all other conditions are true...)

Henning

Warren McInnes
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.
March 11, 2013

Thank you, will give it a try as soon as i can

JamieA
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.
March 11, 2013

Upvoted, but I think you need to back this up with something else so the users understand why they can't do the transition. The "something else" could be eg a scripted field, or the intenso conditions validator.

3 votes
Warren McInnes
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.
May 1, 2013

Hi Jamie, Your Escalation Service/script is excellent and works well. Thank you!

2 votes
Henning Tietgens
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.
March 3, 2013

You could implement this as a Script Runner service which runs once a day to test if the condition is meet and transition the matching issues. For more specific advice or guidance we need more specific info where you're stuck :-)

Henning

Warren McInnes
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.
March 3, 2013

a service that runs once a day would work. What specific info do you need?

Henning Tietgens
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.
March 3, 2013

If this is enough, I'm fine :-) Implementing a Groovy service is already provided by Script Runner, look here, there are also some good examples.

Warren McInnes
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.
March 3, 2013

Could you give some guidence of what the code should look like for the service?

Henning Tietgens
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.
March 3, 2013

You don't have to provide some "special" code to create a service. It's a normal Groovy script implementing your logic and actions. You save this script to a folder on the server, install a Script Runner service within JIRA and define the path to the script and the intervall, how often the script should run.

Within the script you first have to find the issue you want to transition. You should narrow down the list of possible issues as much as possible through a JQL search. Example code see here.

I think, from your description above, for the resulting issue you have to calculate if they are due by reading the two fields Due Date (through issue.getDueDate()) and Frequency. Pay attention, that the value of a select list is an Option and you have to call getValue() on the Option to get the real value. See here for examples on reading customfields.

For the last matching issues you have to transition them as described here.

0 votes
Graham Horsman October 28, 2013

This works really well for us. Thanks Jamie!

0 votes
JamieA
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.
March 19, 2013

The thing I was talking about it is available now... kind of beta though: https://jamieechlin.atlassian.net/wiki/display/GRV/Escalation+Service

0 votes
Warren McInnes
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.
March 11, 2013

Hi Henning,

Our Workflow basically closes a subtask then transitions the main task into "Monitor & Close"(Status) and needs to continue to be open for x days(must be vaiable or perhaps pre-defined) then the option to be closed should become available?

is this possible and how?

0 votes
Henning Tietgens
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.
March 11, 2013

Hi, you can script a condition for the workflow button depending on a date.

0 votes
Warren McInnes
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.
March 11, 2013

Hi Jamie,

Any further progress on your escalation service?

Do you know what would be the simplest way to implement the an workflow transition button on an issue remains hidden until X days have past?

So therefore i would like the option for issues to be manually be closed, but only after x amount of days?

Thanks in Advance

0 votes
JamieA
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.
March 3, 2013

Week or so.

0 votes
Warren McInnes
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.
March 3, 2013

Ah i see, When do you expect your escalation service to be ready?

0 votes
JamieA
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.
March 3, 2013

And as Henning says, it needs to be a service, not post-function or anything else.

0 votes
JamieA
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.
March 3, 2013

No, I abhor jelly. It will be similar to what Henning descibes below. You specify a jql query, a frequency, issue action(s) for matching issues, and optionally additional code to run, such as update custom fields or whatever. The idea is it would be used instead of "jelly escalation".

0 votes
Warren McInnes
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.
March 3, 2013

My thought was to write a groovy post-function, but not sure how and where to use it. I thought of fast-track but it requires and action to be automated, whereas i would like something to do the auto-transition automatically? can you describe your "escalation service" ,How will it work in this situation? will it auto-transition based on a condition? we don't want to use jelly scripts - will this included jelly scripts?

0 votes
JamieA
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.
March 3, 2013

The bits of code you need are around, eg IssueService, run a jql query. Can you be more specific?

I'm currently working on a configurable "escalation service", which will probably be able to do what you need with minimal code, you might just want to wait for that.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events