How to create a workflow validation rule with scriptRunner

jose de jesus torres torres March 18, 2024

Hi

I have encountered an issue with the workflow in ScriptRunner. I'm unsure about how to utilize the 'Transition' context variable. I've added this script as a validation rule in the 'Create' transition. However, when attempting to test the script, the console displays the following error: 'Evaluation failed: "transition" - identifier not available in context'.

1 answer

0 votes
Sean Chua _Adaptavist_ March 19, 2024

Hey @jose de jesus torres torres ,

Can you share more about what you are trying to do etc?

You mentioned script as well, just based on what you have shared, not much info to look at:

error: 'Evaluation failed: "transition" - identifier not available in context'.

With ScriptRunner for Jira Cloud Validators, it would use Jira Expressions. There are some existing (Jira Expressions Examples ) on our page...but yeah.. not quite sure what you are trying to do to help.

Regards,
Sean

jose de jesus torres torres March 19, 2024

Hi Sean, 

Well, I need to get the name of the target transition. Reading the JIRA documentation (https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference), I found the context variable type "transition", however I don´t know how to use it. This is my JIRA expression: transition.to.name == 'Analisis, Prototipado y Reglas de Negocio'

Sean Chua _Adaptavist_ March 19, 2024

Hi Jose,

Validators and Conditions are quite similar with the only difference being:

  • Validator checks to see if requirements are met to allow transition
    (Eg: You require one linked issue to be able to transition to "Done"). An error message will pop up if requirements not met.
  • Conditions make sure requirements is met before a transition can be used/seen.
    (Eg: Users from X Group can transition to "Special Case"). Users not part of this group will not be able to see the status "Special Case" as an option to transition.

So for your case, I am assuming that you are trying to validate that some requirement need to be met to be able to transition to "Analisis". The expression needs to be (true) to allow the transition, if it is (false) then you can't transition.

In that case, using the same require one linked issue example : issue.links.length > 0

If the issue has 1 (or more) linked issue, then the issue will be able to transition.

if the issue has 0 linked issue, then an error message will pop up.

I hope the explanation helps. 

Regards,
Sean

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events