Automate transition in a workflow,

Tomasz Jurek June 1, 2014

I need to automate transition of jira workflow. Lets say if no action on ticket is taken then it automatically gets transferred to another step in workflow.

I tried with conditions, validators, Jira Workflow Tollbox, Misc Workflow Extensions - I dont know I give up

HELP!

3 answers

0 votes
Tomasz Jurek June 8, 2014

Thanks for reply, ideally I get back to this in current week if not see you in July (vacations at last !)

Jelly script might be a too big level of abstraction for me.

0 votes
Paresh Gandhi
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.
June 2, 2014
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Logger
import static org.apache.log4j.Level.DEBUG
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.index.IssueIndexManager

class invoketransition extends AbstractIssueEventListener {
        Logger log = Logger.getLogger(invoketransition.class)
        @Override
        void issueUpdated (IssueEvent event) {
                log.setLevel(org.apache.log4j.Level.DEBUG)
                def field = event.getChangeLog().getRelated('ChildChangeItem').any{ it.field.toString().equalsIgnoreCase("Assignment Group")}
                if (field){
                        log.debug "Group field has changed"
                        Issue issue = event.getIssue();
                        def issuestatus = issue.getStatusObject().getName().toUpperCase()
                        log.debug "status of issue" + issuestatus
                        if (issuestatus == "WAITING FOR SUPPORT" || issuestatus == "WAITING FOR CUSTOMER" || issuestatus == "WAITING FOR TRIAGE"){
                                int actionid = 0
                                if (issuestatus == "WAITING FOR SUPPORT")
                                        actionid = 881
                                else if (issuestatus == "WAITING FOR CUSTOMER")
                                        actionid = 891
                                else if (issuestatus == "WAITING FOR TRIAGE")
                                        actionid = 871

                                log.debug "actionid " + actionid

                                def user = issue.getAssignee()
                                ComponentManager componentManager = ComponentManager.getInstance()
                                IssueService issueService = ComponentManager.getInstance().getIssueService()
                                IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
                                TransitionValidationResult validationResult = issueService.validateTransition(user, issue.id, actionid, issueInputParameters)
                                issueService.transition(user, validationResult)

                                log.debug "Invoked change assignment group transition"
                        }
                }
        }
}

above code may help you.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 1, 2014

The Jira Toolkit has an auto-tranistion listener - the use case for that was originally "someone comments on a closed issue, want to reopen it". But that really does mean waiting for events on issues. If you're struggling with using that, you might want to tell us what you've configured in it.

You might want to look at the Script Runner which also implements a fast-track transition, but I suspect the auto-transition listener is the one you really want.

Tomasz Jurek June 1, 2014

Thank you for your swift reply..basically I assumed that only by conditions and validators I would recieve auto-transition.

I'm looking at toolkit and script runner right now...get back to you asap.

Tomasz Jurek June 1, 2014

Hey Nic.

Maybe you can share a lil bit of your karma...problem is I'm not developer..so once I start to do research on this my synapsis are swelling and I get headache...

Having this said, whichever script runner or toolkit solution would you be able to show me solution for such a requirement:

regardless of point in workflow or state, if ticket in jira raised has reached 48h from creation (or current date or time, or time elapsed alternatively) it will get auto transited into next state in workflow

I guess this is something easy to facilitate but I wasnt borned like that :( Thanks in advance..

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 2, 2014

Ok, where are you stuck in the "auto transition listener" documentation?

Tomasz Jurek June 2, 2014

Morning Nic.

If we consider this: https://ecosystem.atlassian.net/wiki/display/JTOOL/Auto+Transition+Listener

I added listener I can find Event ID and Action ID, project Key. I cannot find matching status as those are coming from different schemes (workflows).

I filled Action that triggered the IssueUpdated event to transition. Not sure if this is correct.

My workflow would be like this ticket is created RFC -> Change Review (if no one rejects it in 48h) -> SCHEDULED. From Change review state there are other possible transitions. But only this one we'd like to have automated.

So I assume I have added this listener but what does it give me in advance?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 2, 2014

Ok, I just want to step back for a second.

What are you using to trigger this automatic transition? I.e. When do you want it to happen?

(You've actually got most of what you need, I just want to make sure we're doing the right thing for you)

Tomasz Jurek June 2, 2014

Once ticket will be manually progressed to Change Review state then I want basing on time elapsed 48h to AUTO-transition it to scheduled state.

If users objects then they should reject it manually, otherwise it lands in scheduled state, team gets notified and proceed with implementation.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 2, 2014

I'm glad I asked.

The auto-transition listener requires an event to act as the trigger. "time passed" is not an event, so there's nothing for a listener to hook into.

You need a slightly different approach to this. Sorry, I should have asked this sooner.

First, make sure your workflow has the transition you want to use (I think that you already have this - you want to do Change Review -> Scheduled)

Secondly, create a filter that captures all the issues that you might want to automatically transition. Assuming you want the transition I mentioned above, then your filter is probably "status = "Change Review" and updated < -2d"

Third, use a "jelly escalation" script as a service. Jelly scripts can do a number of things to Jira issues, and a common use is "push issue through transition on a schedule". See https://confluence.atlassian.com/display/JIRA/Jelly+Escalation

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events