Multi Checkbox in Simple scripted validator

Hi,

I have a custom field called 'Attributes' that is a Multi Checkbox. This has two options currently, 'Ongoing Issue' and 'Review Required'.

I have another customer field 'Reviewer' which is a user picker type.

I want to have a validation on creating an issue that if the 'Review Required' check box is checked then the 'Reviewer' field must have a valid user or at least is not empty.

Currently I have this in the condition field...

cfValues['Attributes'] == 'Review Required' && cfValues['Reviewer'] == null

...this doesn't work though, always seems to evaluate to true as I get the error message I defined.

I also read in another forum that I need to treat the Multi Checkbox differently so I tried...

cfValues['Attributes'][0] == 'Review Required' && cfValues['Reviewer'] == null

cfValues['Attributes'][1] == 'Review Required' && cfValues['Reviewer'] == null

cfValues['Attributes'][0] == 'Yes' && cfValues['Reviewer'] == null

...all gave the same issues as above.

What am I doing wrong here?

Thanks

2 answers

1 accepted

1 vote

Have a look at using power assertions to debug (you need the latest version) - https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-PowerAssertions

There is an example in the section above for multiselects - to see if review required is checked use:

cfValues['Attributes']*.value.contains("Review Required")

Not tested but you probably want something like

cfValues['Attributes']*.value.contains("Review Required") ^ cfValues['Reviewer']

That means, review required is checked in the field "attributes" exclusive or Reviewer is null.

Thanks for the info...

I tried

cfValues['Attributes']*.value.contains("Review Required") ^ cfValues['Reviewer']

but it never evaluates to true, then I tried this

cfValues['Attributes']*.value.contains("Review Required") ^ cfValues['Reviewer'] == null

It evaluates to true when the checkbox is checked and the reviewer field has a user but not when the reviewer field is empty and the checkbox is NOT checked.

Does the validation evaluate to ok when the condition evaluates to true or false?

Henning Tietgens Community Champion Apr 02, 2013

If the condition evaluates to true the transition is visible.

So when I use the condition tester I get the following.

assert cfValues['Attributes']*.value.contains("Review Required") ^ cfValues['Reviewer'] == null
       |       |               |     |                           | |       |            |
       |       |               |     true                        | |       null         true
       |       |               [Review Required]                 | [Attributes:[Review Required], Baseline End:null, Baseline Start:null, Budget Bucket:null, Due Time:null, DueTime:null, Epic/Theme:null, Flagged:null, Gantt Options:null, Issue Owner:neivaldocacador:1, Latest End:null, Latest Start:null, Perc. Complete:[0%], Planned End:null, Planned Start:null, Primary Account:J12345, Project Phase:null, Responsible Department:200 - Engineering, Review Results:Required, Reviewer:null, Scratch Pad:null, Secondary Account:Account A, Units:null, Zephyr Teststep:null, issueFunction:null]
       |       [Review Required]                                 false
       [Attributes:[Review Required], Baseline End:null, Baseline Start:null, Budget Bucket:null, Due Time:null, DueTime:null, Epic/Theme:null, Flagged:null, Gantt Options:null, Issue Owner:neivaldocacador:1, Latest End:null, Latest Start:null, Perc. Complete:[0%], Planned End:null, Planned Start:null, Primary Account:J12345, Project Phase:null, Responsible Department:200 - Engineering, Review Results:Required, Reviewer:null, Scratch Pad:null, Secondary Account:Account A, Units:null, Zephyr Teststep:null, issueFunction:null]

Not to sure how to interpret the results

So you have two statements: A ^ B. It's saying A and B are true, so A ^ B is false. Which is what you want I think. Ie the multiselect has review required, but the reviewer is null, so just remove the assert and add your error message.

Equally this will be false if there is a reviewer but the checkbox is not selected.

Or possibly you want:

def reviewRequired = cfValues['Attributes']*.value.contains("Review Required")
(! reviewRequired) || (reviewRequired && cfValues['Reviewer'])

This was the final condition

(cfValues['Attributes'] != null && cfValues['Attributes']*.value.contains("Review Required")) ^ cfValues['Reviewer'] == null

My issue was not checking for the null on the 'Attributes', it was causing an exception which mislead me a little.

Thanks Jamie and Henning

0 vote
Henning Tietgens Community Champion Apr 02, 2013

You have to use cfValues[...].getValue() to get the value of fields with predefined options.

Henning

Henning Tietgens Community Champion Apr 02, 2013

If you're not sure, you can debug the class name cfValues[] returns.

log.error "returned class: " + cfValues['Attributes'].class.name

and look up the class within the JIRA API.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

252 views 0 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you