Get current workflow transition ID scriptrunner

zerobarat1 September 8, 2019

I need to get the workflow transition ID that the currently logged-in user is trying to trigger from JIRA in a script using scriptrunner.

 

I tried using transientVars["actionId"] but it's not a valid option when running the script from a file, unfortunately. 

I can't really find a lot on this on how to achieve this.

What I need is just the ID, not the name or linked steps or potential next transitions, but the one that the user is triggering from JIRA.

Thanks!

1 answer

1 accepted

0 votes
Answer accepted
Ilya Turov
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.
September 9, 2019

Hello,

I've tested it both from inline function and from file and it works alright.

Can you provide a little bit more context?

zerobarat1 September 9, 2019

Hello @Ilya Turov , you are right, I made some additional checks this morning and it does work, but not when you're trying to enclose your entire code in a class. Do you know of any limitations that Scriptrunner has when running class file from a file on the server? I am trying to understand what I am doing wrong, right now :(.

Ilya Turov
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.
September 9, 2019

I would say, that since transientVars is a binding variable, and postfunction is a class itself, you can't use it only in a "main context" or something.

If you want to use it in a class, guess you would need to add it to it's constructor like this:

class test {
def actionId
test(transientVars) {
actionId = transientVars["actionId"]
}
}
def a = new test(transientVars)
a.actionId
Like Polina Semykina likes this
zerobarat1 September 9, 2019

Thank you, you are correct! This has helped me quite a lot. @Ilya Turov Just one more question: I want to make this re-usable from a CRON in JIRA. If I get rid of the class and arrange the code in methods only, do you think I will run into problems then because I no longer have a class? The Systems part of JIRA is completely separate from scriptrunner and it will not run through a post-function. Thanks!

Ilya Turov
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.
September 9, 2019

Yeah, pretty sure there's no binding transientVars for services (basically, it's same thing you can run from script console). So you won't be able to execute same piece of code via postfunction and via CRON.

If it's something really large you want to reuse, you can try using concept of script roots, creating separate class, using it in both postfunction and CRON service, but having different logic in main parts of those two scripts (eg having some transientVars stuff in postfunction, but not in CRON).

zerobarat1 September 9, 2019

Thank you so much! @Ilya Turov 

Suggest an answer

Log in or Sign up to answer