Groovy Script for Linked Issue Transition

AKASHB June 25, 2013

I want to write a groovy Script in which, on certain transition of issue type 1 which follows some workflow, when state changes from state 1 to state 2 then linked issue with that ticket should move its from state 1 to state 2 which follows other workflow say workflow 2.

Can any body help me out with this?

1 answer

1 accepted

4 votes
Answer accepted
Christian Czaia _Decadis AG_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 25, 2013

You could search the forum. There have been several questions on this matter:

I'v been trying to do the same and ended up with sth. like this. Don't know if it's good but bascially transforemd existing scripts (I'm using Jamies Script Runner Plugin BTW)

// package com.test.transitionSubtask


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

def componentManager = componentManager.getInstance()
def issueLinkManager = componentManager.getIssueLinkManager()


import org.apache.log4j.Category
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;

 
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG) 
log.debug "debug statements"

log.debug "Hello" 
 
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );



issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
        if (issueLink.issueLinkType.name == "Blocks") {
        log.debug ("Linktyp: " 				+ issueLink.issueLinkType.name)
		log.debug ("Status parent: "		+ issueLink.destinationObject.statusObject.name)
		log.debug ("ID parent: "  			+ issueLink.destinationObject.getId())
		log.debug ("Schlüssel Verlinkung: " + issueLink.destinationObject.getKey())
		log.debug ("Lösung Verlinkung: " 	+ issueLink.destinationObject.getResolutionObject().getName())

		// Nur wenn bestimmte Lösung
			if (issueLink.destinationObject.getResolutionObject().getName() == "Fixed"){
		// Transition einleiten
				workflowTransitionUtil.setIssue(issueLink.getDestinationObject());
    		    workflowTransitionUtil.setUsername(currentUser);
    		    workflowTransitionUtil.setAction (3)    // 5 == RESOLVE ISSUE

		// Add a comment so people have a clue why the child has been closed 
    		    CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
    		    String comment = "*Resolving* as a result of the *Resolve* action being applied to the parent.";
    		    commentManager.create(issueLink.getDestinationObject(), currentUser, comment, true);

        // validate and transition issue
    		    workflowTransitionUtil.validate();
    		    workflowTransitionUtil.progress();
					}
                }
else {log.debug("Hello CCCCCCCC")}
       }

AKASHB July 15, 2013

Thanks for your answer, In my case I have installed Query Custom field plugin, which is a custom field which brings issues from other issue type, so i want to first link this issue and then perform the transition so can anybody help me out.

Darapu Rajesh Babu May 22, 2016

Hi All,

Is the above script working for transitioning linked issues.

Thanks,

Rajesh

 

Darapu Rajesh Babu May 22, 2016

Because I also want to implement it. If it works then please anyone tell me how and where to use this groovy script.

Thanks,

Rajesh

chazt3n October 25, 2016

@Darapu Rajesh Babu, you'll need a script runner plugin, the paid one will save you a lot of time with built in functionality. In the workflow editor you can add a custom script post function that runs this. It may need some tweaking but I'm about to find out and I'll post what I ended up with

Antonio D'Errico February 8, 2017

Hallo @Christian Czaia,

dein Script funktioniert auch wenn zwischen zwei Tickets ein klassischer Link besteht oder nur bei einem Parent+Subtask?

 

Grüße

Toni

JörgS February 14, 2017

Hi,
you can also configure this use case with the Workflow Essentials Plugin and don't need to write a script for it.
Regards,

Joerg 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events