Forums

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

Transition an issue when all linked issue are closed

Swarna Radha
Contributor
August 19, 2019

Hi,

I want to transition main issue to "Open" when all linked issues are closed.

kindly provide me a script. I was using automation rules when linked issue is closed, main ticket is transitioned to Open. But it is not verifying that all linked issues must be closed so that issue is transitioned.

 

Thanks

1 answer

0 votes
DPKJ
Community Champion
August 20, 2019

This is not possible in stock Jira, you will plugins like

Using them you can post functions for workflow, which will solve your problem.

Swarna Radha
Contributor
August 20, 2019

Hi, I am using Script runner.

Please see my code below:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
import org.apache.log4j.Category
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

log.setLevel(org.apache.log4j.Level.DEBUG)

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
log.debug "Original: ${issue.getId()}, ${issue.getKey()}. DETECTED " + issue.getStatus().name

List<IssueLink> allInIssueLink = issueLinkManager.getInwardLinks(issue.getId());
for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next();
def linkedIssue = issueLink.getDestinationObject();
log.debug "linked: ${linkedIssue.getId()}, ${linkedIssue.getKey()}. DETECTED " + linkedIssue.getStatus().name
if (linkedIssue.getStatus().name.equals("Open")) { // STATO della issue collegata
log.debug "linked Content: ${linkedIssue.getId()}, ${linkedIssue.getKey()}."

//We can transition the parent ticket
log.debug "start transition"

workflowTransitionUtil.setIssue((MutableIssue) linkedIssue);
workflowTransitionUtil.setUserkey(currentUser);
workflowTransitionUtil.setAction (221); //Transition ID
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();

log.debug "end transition"
}

}

 

The issue is not transitioned.

Suggest an answer

Log in or Sign up to answer