Hello,
Im currently working on a project to transition an issue on comment using script listener "fire generic even" but i cant seem to get the following code working.
I've selected the events "Issue Commented" and placed the following code:
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 == "Escalation") { if (status == "Response") // Email Sent { transition == "Resolve" // Resolve } } 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") } }
and place event as "Generic Event", but it doesnt seem to work, when attempting to comment, the comment section just load.
Hopefully someone can debug this would be a massive help.
Many thanks,
Pon
Hi Pon!
I deleted unused variables and optimised code. See my comments:
package com.netic.listener import com.atlassian.jira.issue.Issue import com.atlassian.jira.util.JiraUtils; import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; class ExampleListener extends AbstractIssueEventListener { WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); @Override void workflowEvent(IssueEvent event) { Issue issue = event.issue; //Zverev: it is better to place check at start if( (issue.getIssueTypeObject().getName() != "Escalation")&&(issue.getStatusObject().getName()!= "Response")) return 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 = ((String) event.getUser()).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 == "Escalation") { if (status == "Response") // Email Sent { transition == "Resolve" // Resolve Zverev: transition in Integer ype } } if (transition != 0 ) { // Transist Issue workflowTransitionUtil.setIssue(event.issue); workflowTransitionUtil.setUsername(currentuser); workflowTransitionUtil.setAction (transition) //Int is requred, but Integer is set // 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") } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.