Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to use Script Runner (Post Function) to clone an issue but only when a link does not exist?

I've added a Post Function - Script Runner function to one of the workflow transition steps to clone the issue and would like to only perform the clone if none of the issue links have an issue type of 'Change Control' for example.

I've found a lot of example on the internet but none seem to cover finding all the issue links then checking each issue type.

thank you

1 answer

This is a script I use to transition linked issues.

I assume you can just adjust to use it as a condition


import com.atlassian.jira.user.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.workflow.IssueWorkflowManager
import com.atlassian.jira.util.JiraUtils
import com.opensymphony.workflow.loader.ActionDescriptor
import com.atlassian.jira.ComponentManager

//Get the current Issue
Issue issue = issue;

//Get User
def userManager = ComponentAccessor.getUserManager()
def sdUser = userManager.getUserByKey('sdagent')

List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
IssueWorkflowManager issueWflwMan = ComponentManager.getComponentInstanceOfType(IssueWorkflowManager.class);

//Define action name for parent issue
String actionName = "Resolve";

List<Issue> allParentIssues = new ArrayList<Issue>();
List<Issue> allChildIssues = new ArrayList<Issue>();
Boolean allClosed = true;
int actionID;

//you might want to change allOut with allIn depending on the link type
//Get all Parent Issues
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
    IssueLink outIssueLink = (IssueLink);


//here is the iteration for each linked issue, check again inward or outwards links
for(Issue parentIssue : allParentIssues){
    List<IssueLink> allInwardIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(parentIssue.getId());

    //Get all linked Issues
    for (Iterator<IssueLink> inIterator = allInwardIssueLink.iterator(); inIterator.hasNext();) {
        IssueLink inIssueLink = (IssueLink);

    //If all  closed, update the parent issue
    if(allClosed) {
        MutableIssue mutableParentIssue = (MutableIssue) parentIssue;
        if('Service Center'){
            def disallowedStatuses = ['Resolved','Closed','Done','Cancelled']
                Collection<ActionDescriptor> coll = issueWflwMan.getAvailableActions(parentIssue, sdUser);
                for(ActionDescriptor ad : coll) {
                    if(ad.getName().equals(actionName)) {
                        actionID = ad.getId();

Thank you and I'll give it try

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

219 views 0 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you