Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Capture the Transition name/title in Groovy script?

Bob November 14, 2013

Working with Groovy script in a workflow, is there a way to capture the Transition name/title when clicked via script?

Working on one script to trigger certain actions based on what transition was selected within a workflow. When a transition is clicked, I would like to have a Groovy script act similar to a listener by testing the "button clicked" to decide what needs to be done. Rather than having hard coded scripts per transition, I am looking to have one script that will respond accordingly.

Any assistance is greatly appreciated.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Bob November 18, 2013

So after various views and no answers, I figured it out. My main issue was what my import statements needed to included.

import com.atlassian.jira.ComponentManager;
import org.apache.log4j.Category;
import com.atlassian.jira.workflow.JiraWorkflow


ComponentManager componentManager = ComponentManager.getInstance()
JiraWorkflow workflow = componentManager.getWorkflowManager().getWorkflow(issue);
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"]).getName()

// test what transition "button" was clicked in the workflow
if (actionName == "Test Me"){
        System.out.println "Heck Yeh!"
} else {
        System.out.println "Oh No!"
}

System.out.println "transientVars: $transientVars";

zaharovvv_suek_ru
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 8, 2018

@Bob Where have you declared 'transientVars["actionId"]' ?

Console highlights as error this variable 'transientVars["actionId"]'.

Bob June 8, 2018

Weird, I got the notification for this but I am not the same Bob in the post. I wonder what thats about.  

Kleber Fonseca September 17, 2018

@zaharovvv_suek_ru

 

Hi. It's missin "as int". See below

 

wfd.getAction(transientVars["actionId"] as int).getName()

 

It works...

Kleber Fonseca September 17, 2018

missing

Vineela Durbha February 12, 2019

@Bob31

JiraWorkflow workflow = workflowManager.getWorkflow(issue);
String workflowName=workflow.getName();
log.debug("workflow name" +workflowName)

def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars['actionId'] as int).getName()

 

It is throwing an exception as below. 

groovy.lang.MissingPropertyException: No such property: transientVars for class:

Can you please help me

Like Polina Semykina likes this
Christoph Beer August 20, 2019

Instead of Component Manager

ComponentManager componentManager = ComponentManager.getInstance()
JiraWorkflow workflow = componentManager.getWorkflowManager().getWorkflow(issue);

you could use the Component Accessor as well. 

 JiraWorkflow workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)

Works for me in a transition Script. 

 

thanks for the previous postings

Like mahelou likes this
TAGS
AUG Leaders

Atlassian Community Events