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?
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:
Best Regards,
Felipe
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.