A hint - Dont let any "Post Function" call in this script "Fire a Issue Commented event that can be processed by the listeners." - this will make a loop, as the Listener call itself etc etc

// Class to Transist issues on Comments

package com.netic.listener

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.util.JiraUtils;
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;

class ExampleListener extends AbstractIssueEventListener {
    ComponentManager componentManager = ComponentManager.getInstance();
    def issueLinkManager = ComponentAccessor.getIssueLinkManager();
    def authContext = componentManager.getJiraAuthenticationContext()

    WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
    @Override
    void workflowEvent(IssueEvent event) {
       String issueid     = event.issue.id
       String issuekey    = event.issue.key
       String status      = event.issue.getStatusObject().getName()
       String eventid     = event.getEventTypeId()
       String issuetype   = event.issue.issueTypeObject.name
       String currentuser = event.getUser()
       currentuser = currentuser.split(":")[0]
       Integer transition = 0
       System.out.println("script=Listener.groovy IssueKey=" + issuekey + " action=StartScript")
       System.out.println("script=Listener.groovy IssueKey=" + issuekey + " currentUser=" + currentuser)
       System.out.println("script=Listener.groovy IssueKey=" + issuekey + " eventid=" + eventid)
       System.out.println("script=Listener.groovy IssueKey=" + issuekey + " issuetype=" + issuetype)
       System.out.println("script=Listener.groovy IssueKey=" + issuekey + " status=" + status)
      if (issuetype == "Task" || issuetype == "Service Request")
      {
        if (status == "Waiting for Customer") // Task And Service Request
        {
          if (issuetype == "Service Request")
	  {
            transition = 831 // 831 = Reply from Customer
            System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 831")
          }
          if (issuetype == "Task")
          {
            transition = 841 // 841 = Reply from Customer
            System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 841")
          }
        }
        if (status == "Resolved" || status == "Closed")
        {
          transition = 3 // 3 = Reopen
          System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 3")
        }
        if (status == "Inactive")
        {
          transition = 761 // 761 = Reply from Customer
          System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 761")
        }
        if (status == "Frozen")
        {
          transition = 801 // 801 = Unfreeze
          System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 801")
        }
      }
      if (issuetype == "Incident") // Incident
      {
        if (status == "Awaiting External Response")
        {
          transition = 211 // 211 = Resume Investigation
          System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 211")
        }
      }
      if (transition != 0 )
      {
        // Transist Issue
        workflowTransitionUtil.setIssue(event.issue);
        workflowTransitionUtil.setUsername(currentuser);
        workflowTransitionUtil.setAction (transition)
        // Validate and transition issue
        workflowTransitionUtil.validate();
        workflowTransitionUtil.progress();
        status = event.issue.getStatusObject().getName()
        System.out.println("script=Listener.groovy IssueKey=" + issuekey + " Issue " + issueid + " transited to new status: " + status)
      }
      System.out.println("script=Listener.groovy IssueKey=" + issuekey + " action=EndScript")
   }
}
    

EventId Table

EventId
Issue Commented6
Issue Updated2

Sample output in catalina.out for an issue that is Transitioned

From "Waiting for Customer" to "Open" - Workflow Transtion number 841 - event number 2 (Issue Updated)

script=Listener.groovy IssueKey=SUPPORT-6730 action=StartScript
script=Listener.groovy IssueKey=SUPPORT-6730 currentUser=neticsupport
script=Listener.groovy IssueKey=SUPPORT-6730 eventid=2
script=Listener.groovy IssueKey=SUPPORT-6730 issuetype=Task
script=Listener.groovy IssueKey=SUPPORT-6730 status=Waiting for Customer
script=Listener.groovy IssueKey=SUPPORT-6730 setting transition to 841
script=Listener.groovy IssueKey=SUPPORT-6730 Issue 27871 transited to new status: Open
script=Listener.groovy IssueKey=SUPPORT-6730 action=EndScript

Sample output in catalina.out for an issue that is not Transitioned

script=Listener.groovy IssueKey=NSP-5692 action=StartScript
script=Listener.groovy IssueKey=NSP-5692 currentUser=neticsupport
script=Listener.groovy IssueKey=NSP-5692 eventid=6
script=Listener.groovy IssueKey=NSP-5692 issuetype=Service Request
script=Listener.groovy IssueKey=NSP-5692 status=Open
script=Listener.groovy IssueKey=NSP-5692 action=EndScript
  • Ingen etiketter