Forums

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

How to set the value of Cascading Select list based on other custom field value

Katia Castiglioni _Hel Maedb_ March 6, 2025

I have to set the value for a cascading custom field where parent value depends on other custom field value.

I used a  Custom script post-function (ScriptRunner) but it doesen't work:

// other field value (single select list)
def cfOther = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11614")
String other = cfOther.getValue(issue).toString()

// cascading cf to set
def cfField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11616")
def fieldConfig = cfField.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find {it.value == other}

issue.setCustomFieldValue(cfField, [option.getOptionId(), option.childOptions[0].getOptionId()])

 someone can help?

1 answer

1 accepted

5 votes
Answer accepted
Felipe Perez _ServiceRocket_
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.
March 6, 2025

Hi Katia,

Good day to you! I'm Felipe from ServiceRocket.

The issue with your script is likely due to how you're retrieving and setting values for a Cascading Select List. Below is the corrected version of your ScriptRunner Post Function to ensure that the Parent Option is set correctly based on another custom field value:

import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.issueService
def optionsManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager

// Get the custom field that determines the parent value
def cfOther = customFieldManager.getCustomFieldObject("customfield_11614")
def otherValue = issue.getCustomFieldValue(cfOther)?.toString()

// Get the cascading select custom field
def cfField = customFieldManager.getCustomFieldObject("customfield_11616")
def fieldConfig = cfField.getRelevantConfig(issue)

// Find the matching parent option
def parentOption = optionsManager.getOptions(fieldConfig).find { it.value == otherValue }

if (parentOption) {
def childOption = parentOption.childOptions?.first() // Select the first child option if available
def cascadingValue = childOption ? [parentOption.optionId, childOption.optionId] : [parentOption.optionId]

// Set the value of the cascading field
issue.setCustomFieldValue(cfField, cascadingValue)
}

Here is what was updated in the script:

  1. Safely retrieves the parent option based on the value of cfOther (single select field).
  2. Ensures the parent option exists before attempting to set it.
  3. Automatically selects the first child option if applicable.
  4. Uses proper issue field setting logic to avoid null pointer errors.

Best Regards,
Felipe

Katia Castiglioni _Hel Maedb_ March 6, 2025

It works!

Thank you so much, Felipe :)

Suggest an answer

Log in or Sign up to answer