Hi All,
I am working to Display Selective options in the Single choice field based on the values selected in Component/s Field.
I tried with the below script but not working and there were no errors in the script.
I added the script to the Components field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS
import com.atlassian.jira.issue.*
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def comp = getFieldById("components")
def value = comp.getValue()
def category = getFieldById("customfield_20550")
def customField = customFieldManager.getCustomFieldObject(category.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (value.toString() == "01 - MAILFLOW")
{
def optionsMap = options.findAll
{
it.value in ["Domains management", "System Administration"]
}.collectEntries
{
[(it.optionId.toString()): it.value]
}
category.setFieldOptions(optionsMap)
}
else if (comp.getValue() == "02 - CLASSIFY")
{
def optionsMap = options.findAll
{
it.value in ["AWS Support", "Mail Format", "Data Model", "Bug Fixing"]
}.collectEntries
{
[(it.optionId.toString()): it.value]
}
category.setFieldOptions(optionsMap)
}
I don't think you need to convert the list of options to a map.
But also, the components formfield value method will return an array of ProjectComponentImpl objects. So simply applying "toString()" on it will not give you predictable results.
This should be better:
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def comp = getFieldById("components")
def components = comp.value as List<ProjectComponent>
def category = getFieldById("customfield_20550")
def customField = customFieldManager.getCustomFieldObject(category.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (components.any { it.name == "01 - MAILFLOW" }) {
def optionsMap = options.findAll {
it.value in ["Domains management", "System Administration"]
}
category.setFieldOptions(optionsMap)
} else if (components.any { it.name == "02 - CLASSIFY" }) {
def optionsMap = options.findAll {
it.value in ["AWS Support", "Mail Format", "Data Model", "Bug Fixing"]
}
category.setFieldOptions(optionsMap)
}
Hi @PD Sheehan ,
Thanks for the answer, I updated and checked, and it's working fine. I completely forgot the component field will return an array.
Thanks,
Vasantakumaar
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.