I am hoping someone can help me understand what is happening and if there is anything that can be done to stop it.
I used this (https://community.atlassian.com/t5/Marketplace-Apps-Integrations/how-to-restrict-field-values-based-on-another-field-values/qaq-p/1094323) question to find the solution to restrict field values based on another field values selection.
I want the CM Deployment Type to vary depending on the CM Classification selected. The solution provided worked great when an issue is created. However, if the user needs to edit the issue using the edit screen, the CM Deployment Type selection appears to change. e.g., If I select CM Classification as Patch, I expect the values Standard and Hotfix for the CM Deployment Type which is what happens. However, if Hotfix is selected and then the issue is edited, the CM Deployment Type changes (appears to change) to the first option in the list which is Standard. The options are the ones I want, I just don't want the selection to change. If the user doesn't notice the selection changed, they could inadvertently change the selection.
Does anyone know why the value appears to change? And how to make it stop?
Jira v8.5.7, Scriptrunner 6.6.0
This is the script I am using and have it mapped to the CM Deployment Classification field.
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
// CM Deployment Classification
int classificationId = 13901 //test 14000 prd 13901
def classification = getFieldById("customfield_" + classificationId)
def classificationValue = classification.getValue()
// CM: Deployment Type
int deployTypeId = 15601 //test 16003 prd 15601
def deployType = getFieldById("customfield_" + deployTypeId)
def deployTypeOptionsManager = ComponentAccessor.getOptionsManager()
def deployTypeCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_" + deployTypeId)
def deployTypeConfig = deployTypeCustomField.getRelevantConfig(getIssueContext())
def deployTypeOptions = deployTypeOptionsManager.getOptions(deployTypeConfig)
if (classificationValue == "Patch"){
def deployTypeMap = ["Standard","Hotfix"]
def deployTypeOptionsMap = deployTypeOptions.findAll {
it.value in deployTypeMap // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
deployType.setFieldOptions(deployTypeOptionsMap)
}
else if (classificationValue == "Minor"){
def deployTypeMap = ["Standard"]
def deployTypeOptionsMap = deployTypeOptions.findAll {
it.value in deployTypeMap // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
deployType.setFieldOptions(deployTypeOptionsMap)
}
else if (classificationValue == "Major"||classificationValue == "Major - Initial Production Deployment"){
def deployTypeMap = ["Standard"]
def deployTypeOptionsMap = deployTypeOptions.findAll {
it.value in deployTypeMap // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
deployType.setFieldOptions(deployTypeOptionsMap)
}
else {
deployType.setFieldOptions(deployTypeOptions)
}