JIRA 6.1.7 groovy validator to check if that at least one custom field is filled

Eric Salonen
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.
February 24, 2014

We are running JIRA 6.1.7 with Groovy script runner. I have placed a validator check (Script validator) that includes the following line (in the Create transtition):

cfValues['System'] is not empty || cfValues['Area'] is not empty

But this seems not to be the correct line as this makes it so that both fields need to be filled. What I want to happen is that the user can decide which field to fill, but at least one needs to be filled. The user can fill both as well if he/she wants.

What would be the code? Any assistance, my coding brain just doesnt want to compute :D

1 answer

1 accepted

2 votes
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.
February 24, 2014

cfValues['System'] || cfValues['Area']

should do it

Eric Salonen
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.
February 25, 2014

Thanks Jamie, legend as always!

Eric Salonen
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 17, 2014

Hi Jamie,

Just returning to this question. Is there a way to use the above script with the ID's of the custom field? Ive ran into problems a few times after this question where the name of the custom field has been changed after and thus the script fails.

Is there a way to use the ID's?

Tsol
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 21, 2014

For getting a reference to custom fields using their IDs you could use the following. The condition i have used in the example below is that custom field is not null. Hope that helps

//xxxxx = custom field id
CustomField customField_test = customFieldManager.getCustomFieldObject( xxxxx );
issue.getCustomFieldValue(customField_test) != null

Suggest an answer

Log in or Sign up to answer