My goal is to have a user create an issue within a specific JIRA project and based on they select within a custom field, will assign a component. The custom field is a database field.
The component and names from within the custom field are not the same. The name of the database custom field is: Client name (17570)
I believe this can be accomplished using a script listener with Scriptrunner add-on. So far I have not been successful with the code below:
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 = [
"Name 1" : "Component 1",
"Name 2" : "Component 2",
"Name 3" : "Component 2",
"Name 4" : "Component 1",
"Name 5" : "Component 1",
]
def issue = issue as MutableIssue
def selectList = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Client name")
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 componentName = componentsMap.get(selectListValue.value)
def component = componentManager.findByComponentName(issue.projectObject.id, componentName)
if (component)
{ componentManager.updateIssueProjectComponents(issue, [component]) }
The error I am receiving:
2020-04-28 13:48:14,563 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2020-04-28 13:48:14,568 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Name 5' with class 'java.lang.String' to class 'com.atlassian.jira.issue.customfields.option.LazyLoadedOption'
at Script522.run(Script522.groovy:299)
If anyone has recommendations, that would be appreciated. Thank you