Hi.
I have two drop down fields:
I would like to create behavior as follows:
If user selects Dev or UAT, Sev 1 is hidden is the drop down. In other words Sev 1 is only available for Prod.
I have managed to hide the whole field Severity, but not sure how to hide just one option from that field
def environmentField = getFieldById(getFieldChanged())
def selectedOption = environmentField.getValue() as String
def cfSeverity = getFieldById("customfield_10120")
if (selectedOption == "Production") {
cfSeverity.setHidden(true)
}
if (selectedOption != "Production") {
cfSeverity.setHidden(false)
}
Can you help?
Thank you.
Hi @Jiri Kanicky,
Below code will help you to hide/show only particular options of select list field, I didn't test this out in my app, it may require minor changes
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
//Get Relevant field and options manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def environmentField = getFieldById(getFieldChanged())
def selectedOption = environmentField.getValue() as String
def cfSeverity = getFieldById("customfield_10120")
def customField = customFieldManager.getCustomFieldObject(cfSeverity.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if(selectedOption == "Production"){
def optionsMap = options.findAll {
it.value in ["Sev 1", "Sev 2", "Sev 3"] // list of options you want to show
}.collectEntries {[(it.optionId.toString()): it.value]}
cfSeverity.setFieldOptions(optionsMap)
}
else{
def optionsMap = options.findAll {
it.value in ["Sev 2", "Sev 3"] // list of options you want to show
}.collectEntries {[(it.optionId.toString()): it.value]}
cfSeverity.setFieldOptions(optionsMap)
}
BR,
Leo
Hi @Leo
Your code works like a charm. I did not have to change anything.
I was able to manage it to the following script myself, but I was not able to figure out where the problem is. Your example really helped me to find the problematic part. I guess I was very close :).
My NOT working script:
//working but for last line
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
def environmentField = getFieldById(getFieldChanged())
def selectedOption = environmentField.getValue() as String
def cfSeverity = getFieldById("customfield_10120")
def severityField = customFieldManager.getCustomFieldObject(getFieldChanged())
def config = severityField.getRelevantConfig(getIssueContext())
def options = ComponentAccessor.optionsManager.getOptions(config)
def allowedOptions = null
if (selectedOption == "Production") {
allowedOptions = ComponentAccessor.optionsManager.getOptions(config).findAll {
it.value in ["High",]
}
}
severityField.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Couple of corrections in your code
1. We need to get the config of field on which options needs to be hidden. here Severity field
so below line
def severityField = customFieldManager.getCustomFieldObject(getFieldChanged())
should be changed to
def severityField = customFieldManager.getCustomFieldObject(cfSeverity)
2. "," should be removed from below line after "High" value
it.value in ["High",]
Hope this helps :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep, this was the missing part I was not able to figure out for several hours :). Thanks Leo!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Leo
Can you please let me know why this is not working for me? Also I want to set None as the default value.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
//Get Relevant field and options manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def detectedinteststageField = getFieldById(getFieldChanged())
def selectedOption = detectedinteststageField.getValue() as String
def cfDevRCA = getFieldById("customfield_18408")
def customField = customFieldManager.getCustomFieldObject(cfDevRCA.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if(selectedOption != "5-Warranty" || selectedOption != "7-PROD"){
def optionsMap = options.findAll {
it.value in ["None", "Ambiguous requirement" , "Code merging" , "Data quality issue" , "Design documentation issue - E2E sheet" , "Design gap - FDD" , "Design gap - TDD" , "Developer Oversight" , "Existing prod issue" , "Impact not analysed - Cross project impact" , "Impact not analysed - Incomplete analysis" , "Impact not analysed - Regression/Defect fix" , "Improper reconciliation" , "Incomplete implementation/defect fix in ST/UAT/Prod" , "Incorrect configuration" , "Incomplete implementation" , "Incorrect logic" , "Incorrect solution" , "Induced due to PRS" , "Interface changes/mismatch" , "Lack of system understanding" , "Package issue" , "Retrofit missed" , "Scenario coverage/Incomplete unit testing"
] // list of options you want to show
}.collectEntries {[(it.optionId.toString()): it.value]}
cfDevRCA.setFieldOptions(optionsMap)
}
else{
def optionsMap = options.findAll {
it.value in ["None", "Ambiguous requirement" , "Code merging" , "Data quality issue" , "Design documentation issue - E2E sheet" , "Design gap - FDD" , "Design gap - TDD" , "Developer Oversight" , "Impact not analysed - Cross project impact" , "Impact not analysed - Incomplete analysis" , "Impact not analysed - Regression/Defect fix" , "Improper reconciliation" , "Incomplete implementation/defect fix in ST/UAT/Prod" , "Incorrect configuration" , "Incomplete implementation" , "Incorrect logic" , "Incorrect solution" , "Induced due to PRS" , "Interface changes/mismatch" , "Lack of system understanding" , "Package issue" , "Retrofit missed" , "Scenario coverage/Incomplete unit testing"
] // list of options you want to show
}.collectEntries {[(it.optionId.toString()): it.value]}
cfDevRCA.setFieldOptions(optionsMap)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Leo
Please can you advise why the same does not work for Components field.
I would need to do the same for Components as for Severity, but just changing the field to Components does not seem to work.
I also tried to follow this article , but that does not seem to work either.
Is there any different mechanism how to restrict values for Components field?
Thank you for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I manage to create script which hides the whole Severity field. Please can you advise how I can hide just one option from the Severity field?
def environmentField = getFieldById(getFieldChanged())
def selectedOption = environmentField.getValue() as String
def cfSeverity = getFieldById("customfield_10120")
if (selectedOption == "Production") {
cfSeverity.setHidden(true)
}
if (selectedOption != "Production") {
cfSeverity.setHidden(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.