Multi Checkbox in Simple scripted validator

Mike Wells
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.
April 2, 2013

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
Answer accepted
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.
April 2, 2013

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.

Mike Wells
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.
April 2, 2013

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
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.
April 2, 2013

If the condition evaluates to true the transition is visible.

Mike Wells
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.
April 2, 2013

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

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.
April 2, 2013

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'])

Mike Wells
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.
April 2, 2013

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 votes
Henning Tietgens
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.
April 2, 2013

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

Henning

Henning Tietgens
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.
April 2, 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
TAGS
AUG Leaders

Atlassian Community Events