How to validate all checkboxes are checked using groovy expresion

Deleted user September 23, 2016

I'm looking to make sure all 4 checkboxes are selected before an issue is transitioned. I edit the workflow select the transition and add a "Scripted (Groovy) Validator"

cfValues['Manager Acknowledgements'][0].getValue() == 'Value 1 '

cfValues['Manager Acknowledgements'][1].getValue() == 'value 2'

cfValues['Manager Acknowledgements'][2].getValue() == 'value 3'

cfValues['Manager Acknowledgements'][3].getValue() == 'value 4'


However I am getting an error: 

An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@3a3029a7: root cause: No such property: cfValues for class: Script1

Do I need to import a library? - JIRA has recognized cfValues for me in script runner previously is there another recognized variable I can use for custom fields?

3 answers

1 accepted

4 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.
September 25, 2016

You can only use cfValues in the "Simple Scripted Validator". I guess you are not using that. 

It doesn't seem like the best way anyway, you need to keep the strings in sync. Here is a custom validator that checks that all possible options are checked:

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def fieldConfigSchemeManager = ComponentAccessor.getFieldConfigSchemeManager()

def cf = customFieldManager.getCustomFieldObjectByName("Checkboxes") // modify name of checkboxes field
def config = fieldConfigSchemeManager.getRelevantConfig(issue, cf)
def allOptions = optionsManager.getOptions(config)

if (issue.getCustomFieldValue(cf) != allOptions) {
    throw new InvalidInputException(cf.id, "Check all boxes")
}
siva October 30, 2019

@JamieA 

This Works ,

 

and any possibility you can add another valildation to the same script.

ex:  (  or validates if the user is in specific project roles in jira )

Software N3B August 5, 2020

Thank you for this solution! This seems to have worked in forcing all checkbox options to be checked before the issue is created.

 

However, we see a generic error at the top of the request with no specific field validation when not all options are checked.

 

How can we add a validation message to the field itself to help the user see where their error is?

0 votes
Tanu April 27, 2020

@JamieA , Hi, i am using "Checklist" plugin, and i have to write a condition in Listener to validate if all the items are checked in checklist.

can you please help. 

0 votes
Deleted user September 26, 2016

Hi @Jamie Echlin [Adaptavist] 

This worked. Thanks !

Erwin Manuel February 12, 2017

Hi Niamh,

What are the steps you took to fix the script? We need a similar solution...

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 21, 2017

Did not the script in my answer work?

arama mihai
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.
September 12, 2018

Hi Jamie,

I'm using the script you suggested, and it seems to be throwing the error even if all the boxes are selected. Do you know if anything has changes since you posted it?

 

Thank you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events