Groovy Script for Linked Issue Transition

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

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")}
       }

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.

Hi All,

Is the above script working for transitioning linked issues.

Thanks,

Rajesh

 

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

@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

Hallo @Christian Czaia,

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

 

Grüße

Toni

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

174 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you