Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

About usage of scriptrunner listener.

Jason Liu
Contributor
February 10, 2022

We have a need that a cloned issue's workflow status change can trigger its source issue's status change. For example, we have 2 projects, A and B. We create an issue name A-1 in A and clone it as A-2. Then we move A-2 to B as B-1. We want to have B-1 status change can trigger A-2 status change. The 2 projects have different workflows. We have made a scriptrunner listener and it was created for auto-cloned issues. But now we need to manually clone the issue since we need it also from B-A. So that it won't produce too much duplicated issues. Could someone help to check my script and tell me how to change it? I hope that I have cleared the problem. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.workflow.WorkflowTransitionUtilFactory
import com.opensymphony.workflow.loader.ActionDescriptor

Issue issue = event.issue
List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(event.issue.getId());

for (Iterator outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {

def currentdata = outIterator.next();
//Issue haha1 = (Issue) haha;

IssueLink currentissue = (IssueLink) currentdata;
//log.warn("issue:"+issue.getStatus().name);
//log.warn("linkissue:"+haha1.getStatus().name);

MutableIssue Sourceissue = ComponentAccessor.getIssueManager().getIssueObject(currentdata.getSourceId());
//log.warn("Sourceissue:"+Sourceissue.getStatus().name)

WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
//log.warn(issue.getStatus().name)
//log.warn(Sourceissue.getStatus().name)

if( Sourceissue.getStatus().name == "New"){
//log.warn(Sourceissue.getStatus().name)
if( issue.getStatus().name == "Grooming"){
//log.warn(issue.getStatus().name == "Grooming")
workflowTransitionUtil.setIssue((MutableIssue) Sourceissue);
workflowTransitionUtil.setUserkey(issue.getReporter().key)
workflowTransitionUtil.setAction (11);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
}
else if( Sourceissue.getStatus().name == "Grooming"){
if( issue.getStatus().name == "Open"){
workflowTransitionUtil.setIssue((MutableIssue) Sourceissue);
workflowTransitionUtil.setUserkey(issue.getReporter().key)
workflowTransitionUtil.setAction (31);
workflowTransitionUtil.getActionDescriptor();
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}
}

}

0 answers

Suggest an answer

Log in or Sign up to answer