Use ScriptRunner to modify a select custom field options depending on choice of other custom field Edited

Is it possible to use a Scriptrunner customer field to modify the behaviour between two select list custom fields.

I would like to achieve something like the following:

Custom Field 1 value = 1

Custom Field 2 value dynamically populates options = A, B, C

Custom Field 1 value = 2

Custom Field 2 value dynamically populates options = D, E, F

I would like to avoid using a Cascading Select custom field, because you can't report off it as you can with an individual custom field.

Is this possible? I have tried to look at similar topics and have struggled to find something close to this.

Best wishes

Adam

 

Edit: On reading this advice, I have tried to do this using behaviours, but still no joy with the following script. It simply doesn't seem to change the view of options, no matter what I am selecting in the checkBox.

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

// Point towards Change Result Reason custom field list
def selectList = getFieldById("customfield_15601")

// Point towards Change Result custom field list
def checkBox = getFieldById("customfield_15600")

// Get access to the required custom field and options managers
def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

// Get the checkbox option value as a String
def checkBoxVal = checkBox.getValue()

// Logic to do some actions depending on what check box value is selected
if (checkBoxVal == "Successful") {
// define and set the required options when checkbox A is selected
def optionsMap = options.findAll {
it.value in ["Implemented Successfully"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
} else if (checkBoxVal == "Partially Successful") {
// define and set the required options when checkbox A is selected
def optionsMap = options.findAll {
it.value in ["Bug", "Compatibility Issue", "Configuration Issue", "Deployment Failure", "Did Not Address Reason for Change", "Human Error", "Infrastructure Failure", "Incomplete CHG", "Incomplete documentation", "Management/Business Request", "Methodology not understood or tested", "Other", "Successful", "Testing Failure"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
} else if (checkBoxVal == "Unsuccessful") {
// define and set the required options when checkbox A is selected
def optionsMap = options.findAll {
it.value in ["Bug", "Compatibility Issue", "Configuration Issue", "Deployment Failure", "Did Not Address Reason for Change", "Human Error", "Infrastructure Failure", "Incomplete CHG", "Incomplete documentation", "Management/Business Request", "Methodology not understood or tested", "Other", "Successful", "Testing Failure"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}

 

1 answer

1 accepted

This widget could not be displayed.

What type of reporting are you trying to do that you cant with the cascading select list custom field?  It might be easier to script against a cascading select than to re-invent it.

Thanks Randy, in the end I just got around it by using two separate select list custom fields.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

157 views 1 3
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