Adaptavist Scriptrunner Question

Hello - 

I have a question about modifying an existing Validator that I have configured via Adaptavist Scriptrunner. 

 

The current script I have as a Validator ensures that all check boxes in the Edit screen are checked before the user can make the transition. This script works well. 

 

(cfValues['HR Checklist']*.value as List).containsAll(["a", "b", "c", "d", "e", "f", "g"])

 

I want to build on this script. I have added a tab to the Edit screen with a different selection of check boxes. What I want to do is change the script, in that the values of the check boxes are required based on a custom field value (that has already been selected). 

For example - if custom field value is X, then the user must select all of the check boxes in tab HR Checklist. Those values being "a", "b", "c", "d", "e", "f", "g" 

Like my initial script.

 

If custom field value is apple, then the user must select the apple tab (on Edit screen), and check all boxes "apple", "orange", "pear"

The already populated custom field value determines which tab the user must check all boxes for in the Edit screen, in order to transition the Issue. 

 

I apologize if I am not being clear enough. Any insight/help would be much appreciated. Thanks in advance.  

1 answer

Hi Michael,

If I understand the requirements correctly then a Custom script validator with a script similar to 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.opensymphony.workflow.InvalidInputException

def issue = issue as MutableIssue

def flag = false
def customfieldManager = ComponentAccessor.customFieldManager

def selectListCF = customfieldManager.getCustomFieldObjects(issue).find {it.name == "SelectListA"}
def checkboxCF = customfieldManager.getCustomFieldObjects(issue).find {it.name == "Checkboxes"}

def selectListValue = issue.getCustomFieldValue(selectListCF) as LazyLoadedOption
def checkboxValue = issue.getCustomFieldValue(checkboxCF) as List<LazyLoadedOption>

if (selectListValue.value == "AAA") {
flag = checkboxValue.collect {it.value}.containsAll(["Yes"]) && checkboxValue.size() == 1
}
else if (selectListValue.value == "BBB") {
flag = checkboxValue.collect {it.value}.containsAll(["Yes", "No"]) && checkboxValue.size() == 2
}
else {
// other conditions/combinations
}

if (!flag)
throw new InvalidInputException("Some combination of multiple fields are in error")

will do the trick. 

Please let me know if that helped 

Regards, Thanos

Thanos - 

 

THANK YOU. This is great. I really appreciate it. 

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,138 views 6 19
Read article

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