Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Need a Groovy Script for Validating multi-checkbox field or Current user is in Admin role

siva
Contributor
October 30, 2019

Can any one provide Groovy Script

Need a validator Script for. 

 

1. All the check boxes in the field are selected ( or ) Current user is in developer role in project.

 

Both the conditions need to be in the script.

Tried few scripts but the selection of all the checkboxes wont work.

 

1 answer

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
October 30, 2019

A checkbox returns a list of selected options.

You'll need to compare that list of selected (checked) options against the list of available options for that field in the current context.

This should work in a simple scripted validator (in your workflow)

import com.atlassian.jira.component.ComponentAccessor
//for this you'll need a customfield object for the checkbox field
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName('my checkbox field')
//So that you can get the configuration context
def config = cf.getRelevantConfig(issue)
// and the list of associated options
def cfOptions = ComponentAccessor.optionsManager.getOptions(config)

//then, for good measures, get the list of values in a sorted order so you can compare them. Sorting may not be necessary, I suspect the order will alway be the same, but it can't hurt
cfOptions*.value.sort() == cfValues['my checkbox field']*.value.sort() || isUserMemberOfRole('Developers')
siva
Contributor
October 31, 2019

Thank you,

 

worked out with another script and tested this   no defects.

Like Sebastián Molina Meza likes this

Suggest an answer

Log in or Sign up to answer