Show field value based on the Transition

Gajanan Sasane
Contributor
February 12, 2025

In Jira, DC has a field called "Resolution Category." Now from the workflow,

  1. If I select the transition called "Fixed-No code change," then from the field only the "Customer Environment Issue, Platform or Collector Issue, Documentation Missing or Misleading" options have to be visible; the rest of the options would get hidden.
  2. If I select the transition called "Won't Do," then from the field only the "Product Enhancement, Technical Limitation" options have to be visible; the rest of the options would get hidden.
  3. If I select the transition called "Invalid," then from the field only the "Not Reproducible, Failed Quality Bar, Working as Designed" options have to be visible; the rest of the options would get hidden.
  4. If I select the transition called "No Response," then from the field only the "Internal No Response, External No Response, Devices No Response, Customer No Response" options have to be visible; the rest of the options would get hidden.

Please note that these all transition are closing transition and having different screen

For this, I applied the below script but it is not working as expected. Please let me know if I want to make any changes to the script.



import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.config.FieldConfig

// Get the field and issue context
def resolutionCategoryField = getFieldById(getFieldChanged()) // 'Resolution Category' field
def transitionName = actionName // Workflow transition name

// Ensure transition name is captured properly
if (!transitionName) {
log.error("Transition name could not be determined. Make sure this Behaviour is mapped correctly.")
return
}

// Define valid options for each transition
def resolutionOptions = [
"Fixed-No code change": [
"Customer Environment Issue",
"Platform or Collector Issue",
"Documentation Missing or Misleading"
],
"Won't Do": [
"Product Enhancement",
"Technical Limitation"
],
"Invalid": [
"Not Reproducible",
"Failed Quality Bar",
"Working as Designed"
],
"No Response": [
"Internal No Response",
"External No Response",
"Devices No Response",
"Customer No Response"
]
]

// Get the valid options for the current transition
def validOptions = resolutionOptions[transitionName] ?: []

// Fetch the configured options for the field
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def resolutionCategoryCf = customFieldManager.getCustomFieldObject(resolutionCategoryField.getFieldId())

if (!resolutionCategoryCf) {
log.error("Could not fetch the Resolution Category field.")
return
}

FieldConfig config = resolutionCategoryCf.getRelevantConfig(underlyingIssue)
def allOptions = optionsManager.getOptions(config)

// Filter options based on the transition
def filteredOptions = allOptions.findAll { it.value in validOptions }

// Update the field's options
if (filteredOptions) {
resolutionCategoryField.setFieldOptions(filteredOptions)
} else {
resolutionCategoryField.setFieldOptions([]) // If no valid options, clear the field
}

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.12.18
TAGS
AUG Leaders

Atlassian Community Events