The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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 Champions.
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