ScriptRunner: How can I declare or get a variable transientVars["actionId"] ?

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

I am trying to get Workflow Steps using this documentation:

https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/get-workflow-vars.html

However, when I try to run the code from documentation in Scriptconsole, then I see an error:

import com.atlassian.jira.component.ComponentAccessor

def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"] as int).getName()
log.debug("Current action name: $actionName")

The errors says:
groovy.lang.MissingPropertyException: No such property: transientVars for class: Script3135
at Script3135.run(Script3135.groovy:18)

How can I declare or get a variable transientVars["actionId"] ?

1 answer

1 accepted

1 vote
Answer accepted
Mark Markov
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

Hello @zaharovvv_suek_ru 

transientVars populated only during workflow transition, so there is no method to retrieve it in script console.

In script console you can get id from ActionDescriptor

See my answer in this quiestion
https://community.atlassian.com/t5/Jira-questions/How-to-get-allowable-transitions/qaq-p/815456
Hope it help!

But if you need just for test, you may declare actionId as it is in your workflow configuration.

int actionId = 12

where 12 is transition number in your workflow 

Krishnakumar Parameswaran February 15, 2019

@Mark Markov I've similar query, I was trying to fetch the clone action with a post function.

could you please help on with below code ?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor

int actionId = 201

def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
def actionNme = wfd.getAction(actionId)
log.debug(actionNme)
def actionName = wfd.getAction(transientVars[actionId] as int).getName()
log.debug("Current action name: $actionName")

error :

Message:
groovy.lang.MissingMethodException: No signature of method: com.innovalog.groovy.AugmentedLogger.debug() is applicable for argument types: (com.opensymphony.workflow.loader.ActionDescriptor) values: [Committed]
Possible solutions: debug(java.lang.String), debug(java.lang.String, [Ljava.lang.Object;), debug(java.lang.String, java.lang.Object), debug(java.lang.String, java.lang.Throwable), debug(org.slf4j.Marker, java.lang.String), debug(java.lang.String, java.lang.Object, java.lang.Object)
Stack:
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
script1550236078869870427828.run(script1550236078869870427828.groovy:18)
Mark Markov
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.
February 17, 2019

Hello @Krishnakumar Parameswaran 

As i can see youre using JMWE addon. JMWE have custom logger that accept only strings, so you must convert ActionDescriptor to string, like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor

int actionId = 201

def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
def actionNme = wfd.getAction(actionId)
log.debug(actionNme.toString())
def actionName = wfd.getAction(transientVars[actionId] as int).getName()
log.debug("Current action name: $actionName")
Like Peter Urbansky likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events