Based on CheckBox validation, need to run post function (Run a Transition)

Himanshu Mundra February 17, 2016

I have a Custom field which is of type CheckBox.

What i want is, if all options of that checkbox custom field are selected, then only that post function should run.

 

Could some one please help me 

1 answer

1 vote
Udo Brand
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 17, 2016

What should the post function exactly do?

I personally would use Scriptrunner add-on. It has many build in post functions: See:

https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_post_functions

Himanshu Mundra February 17, 2016

Post Function will run a hidden transition based on condition being true. 

 

Condition is checkbox field shall have all the options ticked.

So need to create a groovy expression for checking that all options are ticked in the custom field 

 

/Himanshu

 

Udo Brand
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 17, 2016
Himanshu Mundra February 19, 2016

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customFields = customFieldManager.getCustomFieldObjects(issue)
customFields.each {cf ->
if (cf.name == '<CUSTOMFIELDNAME>' ) {
return true;
} else {
return false;
}
}

 

*It is not working* 

 

sad

Udo Brand
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 19, 2016

Have you tried Alexeys corrected code snippet?

def customFieldManager = componentManager.getCustomFieldManager()
def customFields = customFieldManager.getCustomFieldObjects(issue)
 
def values = []
customFields.each {cf -&gt;
   if (cf.getName() =~ "Check_" &amp;&amp; cf.getCustomFieldType().getName() == "Multi Checkboxes") {
     values += cf.getValue(issue)*.toString()
}
def validChecks = ['CFO', 'CTO'] //add all your required options here
return values.containsAll(validChecks) ? true : false
Himanshu Mundra February 25, 2016

It gives an error that 

Spread Operator can be used only on Collection type

 

 

Udo Brand
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, 2016

Hmm, how many options do you have?

You could check on each:

cfValues['&lt;Your Field&gt;']*.value in ['Option1', 'Option2', ...]

or maybe

cfValues['&lt;Your Field&gt;']*.value.contains("Option1") &amp;&amp;
cfValues['&lt;Your Field&gt;']*.value.contains("Option2") &amp;&amp;
...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events