Hello,
I am trying to have a post-function that sets the component based off of a required Single List custom field (Ex: selecting the DEB option sets the component to Machien Shop - DEB). However, when executed the custom scriptrunner script fails stating the value is null.
I've tried referencing other similar topics but wasn't able to find the obvious answer.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
//a map with single list options to associated component
def componentsMap = [
"DEB" : "Machine Shop - DEB",
"GR" : "Machine Shop - GR",
"LC" : "Machine Shop - LC",
"LM" : "Machine Shop - LM",
"MC" : "Machine Shop - MC",
"MCP" : "Machine Shop - MCP",
"MCX" : "Machine Shop - MCX",
"MM" : "Machine Shop - MM",
"MXP" : "Machine Shop - MXP",
]
def issue
issue = issue as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def selectList = customFieldManager.getCustomFieldObject("customfield_14161")
//Catches if the field does not exist
if (! selectList) {
return
}
def selectListValue = issue.getCustomFieldValue(selectList) as LazyLoadedOption
//Catches if there is no value for the select list
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 script doesn't show any errors until I run a test issue and it produces the following.
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2019-02-12 07:47:53,807 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-02-12 07:47:53,807 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: PRD-14901, actionId: 1, file: <inline script>
java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object
at Script78.run(Script78.groovy:28)