In this example we want to create a simple Listener for Jira to reopen issues when are closed/done and someone comments the ticket.

Imagine, we have a ticket in status “DONE”

Captura de pantalla 2018-06-05 a las 21.36.29

And there is a “new comment”. Then, the Listener must reopen the issue, and the ticket becomes in “TO DO” status.

Captura de pantalla 2018-06-05 a las 21.31.49

In this example, we can use plugins like Adaptavist Scriptrunner or Groovy Amigo. In this case we will take a look into “Groovy Amigo“. (see more)

For the listener we will go to “Groovy Listeners” section in Jira System panel (once installed Groovy Amigo)

Captura de pantalla 2018-06-05 a las 21.41.46

And we will create the new listener: (In Event “Issue Commented” and for project X)

Captura de pantalla 2018-06-05 a las 21.43.12

with the code


import com.atlassian.jira.issue.Issue;
import org.apache.log4j.Category;
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.MutableIssue;

Issue issue  = event.issue
if (issue.getStatusObject().getName()=="Done")
{

  		WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
 		workflowTransitionUtil.setIssue((MutableIssue) issue)
        workflowTransitionUtil.setUserkey("admin")
        workflowTransitionUtil.setAction(51)
  		workflowTransitionUtil.validate();
		workflowTransitionUtil.progress();
} 

We will need to change the action for the right ID of the transition. The same for the username who will execute the transition, and the name of the final status.

Captura de pantalla 2018-06-05 a las 21.46.54

And now… just try! comment some issue and will be reopened!

By MrAddon

Advertisements
Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s