Hello,
We have the following script listener set up for one of our projects:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
// a map with select list option to Component
def componentsMap = [
"DOORS": ["DOORS"],
"Rhapsody / Design Manager": ["Rhapsody"],
"CS - Rational Change": ["Change (CS)"],
"CM - Rational Synergy": ["Synergy (CM)"],
"JIRA": ["JIRA"],
"Git/Gerrit": ["Gerrit", "Git"],
"Collaborator": ["Collaborator"],
"Klocwork": ["Klocwork"],
"Bullseye / RTRT": ["Bullseye"],
"VectorCAST": ["VectorCAST"],
"Temppo": ["Temppo"],
"Valgrind": ["Valgrind"],
"Ubuntu": ["LX Client"],
"Confluence": ["Confluence"],
"Environment": ["Tools Front Desk"],
"Other Tools": ["Tools Front Desk"],
"Continuous Integration / Delivery": ["Continuous Integration"],
"Data External Exchanges": ["CS External Exchange", "JIRA Data Exchange"],
"Reporting Tools": ["PR Ramp Down"],
"Other Developed Tools": ["_DevOps"]
]
def issue = issue as MutableIssue
def selectList = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Tool/Area")
def selectListValue = issue.getCustomFieldValue(selectList) as LazyLoadedOption
// there is no value for the select list - therefore do nothing
if (!selectListValue) {
return
}
def componentManager = ComponentAccessor.projectComponentManager
def components = componentsMap.get(selectListValue.value)?.collect {
componentManager.findByComponentName(issue.projectObject.id, it)
}
if (components) {
componentManager.updateIssueProjectComponents(issue, components)
}
To briefly explain what it does: We have a custom field, select list type, called 'Tool/Area'. This is basically a way to group several components sometimes. People should select Tool/Area, instead of Components, and when they do that , some component gets added automatically to the issue.
Unfortunately, if you also choose another component, it gets replaced.
How could we change this to append the value to existing components, instead of replacing it?
Thank you!