Forums

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

Options based on resolution value on Edit screen

Maxim Kuyanov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 16, 2023

Can you tell me if it is possible to make a choice of the value of other fields based on Resolution value?
I was able to do this for Resolve but I can't figure out why it doesn't work for Edit screen

import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.issue.resolution.Resolution

@BaseScript FieldBehaviours fieldBehaviours

java.lang.Iterable allowedOptions = null
java.lang.Iterable allowedOptions2 = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//final String dea_result = 'DEA Result'
//final String root_cause = 'Root Cause'
def root_cause = getFieldByName('Root Cause')
def root_cause_cf = customFieldManager.getCustomFieldObjectByName('Root Cause')

def dea_result = getFieldByName('DEA Result')
def dea_result_cf = customFieldManager.getCustomFieldObjectByName('DEA Result')

def res_f = getFieldById("resolution")
def res = res_f.getValue() as Resolution

def config = root_cause_cf.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

def config2 = dea_result_cf.getRelevantConfig(getIssueContext())
def options2 = optionsManager.getOptions(config2)

if (getActionName() == "Resolve")
{
if (res.name.toString() == 'Fixed')
{
allowedOptions = null
allowedOptions2 = null
allowedOptions = options.findAll {
it.value in ["Development issue - Functional", "Development issue - Integration", "Firmware/Third Party", "Lack of Requirements", "Merge", "Not a bug - Broken Environment"]
}
allowedOptions2 = options2.findAll {
it.value in ["Broken Environment", "Test Environment Limitation", "Emulator/Mockup issue", "Deployment Instructions issue", "Known issue", "Floating issue", "No Requirements", "Late Requirements Change", "Wrong Requirements", "No Test Case", "Outdated Test Case", "Wrong Test Case", "Not tested (TC not needed)", "Existing TC wasn't executed", "Caused by late merge/fix", "3rd party issue", "Specific scenario", "TC Execution mistake", "TC Execution blocked"]
}
root_cause.setFieldOptions(allowedOptions)
dea_result.setFieldOptions(allowedOptions2)
}
else if (res.name.toString() == "Won't Fix")
{
allowedOptions = null
allowedOptions2 = null
allowedOptions = options.findAll {
it.value in ["Development issue - Functional", "Development issue - Integration", "Firmware/Third Party", "Lack of Requirements"]
}
allowedOptions2 = options2.findAll {
it.value in ["Known issue", "Floating issue", "No Requirements", "Late Requirements Change", "Wrong Requirements", "3rd party issue"]
}
root_cause.setFieldOptions(allowedOptions)
dea_result.setFieldOptions(allowedOptions2)
}
else if (res.name.toString() == "Not A Bug")
{
allowedOptions = null
allowedOptions2 = null
allowedOptions = options.findAll {
it.value in ["Not a bug", "Not a bug - Outdated Test Case"]
}
allowedOptions2 = options2.findAll {
it.value in ["Not a Bug"]
}
root_cause.setFieldOptions(allowedOptions)
dea_result.setFieldOptions(allowedOptions2)
}
else if (res.name.toString() == "Cannot Reproduce")
{
allowedOptions = null
allowedOptions2 = null
allowedOptions = options.findAll {
it.value in ["Unknown"]
}
allowedOptions2 = options2.findAll {
it.value in ["Floating issue"]
}
root_cause.setFieldOptions(allowedOptions)
dea_result.setFieldOptions(allowedOptions2)
}
else if (res.name.toString() == "Duplicate")
{
allowedOptions = null
allowedOptions2 = null
allowedOptions = options.findAll {
it.value in ["Duplicate"]
}
allowedOptions2 = options2.findAll {
it.value in ["Duplicate"]
}
root_cause.setFieldOptions(allowedOptions)
dea_result.setFieldOptions(allowedOptions2)
}
}

 

1 answer

0 votes
Nic Brough -Adaptavist-
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.
January 21, 2023

Welcome to the Atlassian Community!

Could it be that the resolution field is not on the edit screen? 

It should only ever be put on transition screens.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events