How to validate all checkboxes are checked using groovy expresion

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?

2 answers

1 accepted

1 votes

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")
}

Hi @Jamie Echlin [Adaptavist] 

This worked. Thanks !

Hi Niamh,

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

Did not the script in my answer work?

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,963 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot