how to set complex validators in jira's workflow ?

fabby July 17, 2012

what i want is only user in "SWTL" project role can select except "Fixed" as resolution(like "Reject","Incomple"...), and all sw developers can select "Fixed" as resolution

so i add a script validator as below

isUserMemberOfRole('SWTL') && issue.resolution?.name != 'Fixed'

but the result is strange.

1 one user is of "SWTL" role ,and when choose Fixed,it prevents,but when choose not "Fixed" like "Reject" or "Incomplete" or others. it's ok.

2 if the user is not of "SWTL" role,no matter what resolution he choose,it prevents.

anyone can tell how to write the script condition in "Validators"

3 answers

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 18, 2012

A validator can be thought of as a simple logical question. If the answer is yes, it passes, if the answer is no, it fails.

Your logic says "if the user is a member of the group SWTL and resolution is not fixed". If you think about that carefully, what you're saying is that the person MUST be a member of the group SWTL and the resolution must be something other than fixed. It's the first clause that's killing the other users because they're not in the group...

I think what you need is more like

If (user is member of the SWTL group and resolution != fixed) OR (user is NOT member of SWTL group)

fabby July 19, 2012

thanks Nic,

i wrote the script:

isUserMemberOfRole('SWTL') || (! isUserMemberOfRole('SWTL') && issue.resolution?.name == 'Fixed')

and it works!

Nic do you know some examples about this kind of script,i want to know the syntax of this script.

because i even don't what type of this script,

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 19, 2012

I don't actually know. I have a strong suspicion that you have the script runner plugin installed, because on a standard Jira, you can't just whack in odd lines of code like that. See https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner

Check that, and if it is what you're using, then the docs for it have loads of examples...

JamieA
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.
July 19, 2012

I suspect Nic is right because isUserMemberOfRole is a closure only defined in the script runner plugin afaik. The syntax is groovy, more or less a superset of java, which you can find tutorials for all over the web.

fabby July 22, 2012

yes,i am using script runner.

0 votes
Robert Dzido July 23, 2015

Try Workflow PowerBox plugin and its validator templates. They allow to do grouped validators (like conditions). If you use "Run condition as validator" Validator and "Universal Issue Field Value Validator (including history)" you can reach your goal without scrpting

Here is link to documentation: https://coresoftlabs.atlassian.net/wiki/display/WPB/Product+Overview

0 votes
fabby July 18, 2012

anyone knows,or can provide some examples or syntax of the validate scripts in workflow?

Suggest an answer

Log in or Sign up to answer