Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,502
Community Members
 
Community Events
165
Community Groups

Trying to figure out workflow validator

Edited

Using the example workflow, I am trying to setup a validator.

  1. The example starts with 3 status: To Do, In Progress and Done.
  2. Between To Do and Done, I edited the transition to add a validator. 
  3. I chose "Insight Validators".
  4. I chose "Run a Groovy script".
  5. For the error message I typed "Banned".
  6. For the script, I typed: "return false;". 
  7. I published the changes. 

I expect this validator to make all transition from To Do to Done impossible. Then I go to an issue at "To Do", and click "Done" button... but it failed to block the action. The issue changed from "To Do" to "Done" successfully.

I tried setting the field ID to "status" and changing the script to return error message, "return "Banned";", but it also doesn't work.

What am I missing? 

2 answers

Hi @KC Wong I agree with Dave's response. You can remove the transtion from To Do >> Done , instead of applying a validator. 

If you don't want to remove transtion you can apply a condition that Done won't visible until all condition are met. 

Or 

You can try to apply a transtion screen on Done status, so that validator gives an error message on transition screen, as some validator won't works without transition screen.

On which scenario you want to allow Done transtion from To Do ?

Thanks

V.Y

0 votes

HI @KC Wong welcome to the Atlassian Community!

If I understand your problem correctly, you would like people to prevent to move an issue from status To Do to Done, right?

When you remove the global transition All -> Done and add a transition from In Progress to Done, then people are only allowed to move an issue to Done when it's In Progress.

Is that what you would like to achieve? If not, please explain in more detail.

I'm trying to figure out how to use a validator, blocking To Do -> Done isn't my real objective. 

I tried to setup a validator to block To Do -> Done, using a script to return false or an error message unconditionally, but it is not working at all, I can still change an issue from To Do -> Done.  

Dave Mathijs Community Leader May 05, 2022

Can you share the Groovy script you've used? I won't be able to help you debugging the script, but I'm sure fellow community members can help you sort things out.

The script is simply:

return false;

So that all attempts to click "Done" from "To Do" will be blocked by the validator.

But all issues can go from "To Do" to "Done" successfully. 

 

I also tried to configure a condition. The sample has a condition to check Resolve Issue access rights, I removed it and put an insight script: 

return false;

Expecting the "Done" button to not show up. It didn't show up. 

Then I changed the condition script to:

return true;  

And the "Done" button still does not show up. I also tried return null to no avail. 

 

There is something about these Insight scripts that I seriously do not get.  

To clarify: I am NOT using any apps. I'm using this thingy: 

Capture.PNG

Then I choose Groovy script, as I already stated in my first post. 

Now I realize "Insight" is a different thing entirely. So I installed Script Runner and used it as the validator instead: 

Capture.PNG

But it still doesn't work. It does not block moving from To Do -> Done at all. I tried throwing an Exception in the script, then Script Runner logged it as a fail, but the transition from To Do -> Done is still successful. 

What is the expected behavior of a validator script? Isn't it expecting a String (error message) or boolean in return value?

Script Runner's documentation: https://scriptrunner.adaptavist.com/latest/jira/tutorials/scripted-validators-tutorial.html says there should be an option "Script Validator [ScriptRunner]"

But I see these instead: 

Capture.PNG

Custom script is the one I used. 

Finally, success.

The key points are:

  1. Without Script Runner, it seems there is no way to write a custom validator at all. The other validator options are very specific, can only check access rights, etc. 
  2. Script Runner provides a question mark (Script info) under the script editor. It is from this pop-up that I realize to fail the validation, I have to throw an 
    InvalidInputException. 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you