Hi,
I have 3 custom fields of data types as
1) Subsystem, Select List (single choice) data type
2) Module Owner, User Picker (single user) data type and
3) Release Prime, User Picker (single user) data type
In one of my workflow post function, Based on the "Subsystem" custom field value set, I need to map/set the respective 'Module Owner', 'Release Prime' names to 'Module Owner', 'Release Prime' fields in Jira issues as below::
switch(Subsystem){
case "Agent" : //if this value is updated in the 'Subsystem' custom field
ModuleOwnerValue = "Platform-Support"
RelPrimeVal="Server-release"
break
case "Automation" : //if this value is updated in the 'Subsystem' custom field
ModuleOwnerValue = "Test-Automation"
RelPrimeVal="Client-release"
break
........
........
} // switch
set the ModuleOwnerValue to 'Module Owner' custom field
set the RelPrimeVal to 'Release Prime' custom field
Note: I have to use post function to map the values instead of using the SR Behaviours plug-in as Behaviours are purely client-side... if I clone issues they won't kick in. Please advice what is wrong in my script tried to achieve the same.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
log.setLevel(org.apache.log4j.Level.DEBUG)
@BaseScript FieldBehaviours fieldBehaviours
def componentValue = ""
def relPrimeVal=""
FormField dropdown = getFieldById("customfield_10016") //'subsystem' cusomt field
def myValue = dropdown.getFormValue()
FormField formSubcomponent = getFieldByName ("Module Owner")
FormField Release_Prime = getFieldByName ("Release Prime")
log.error("---------------- subsystem---------------"+dropdown.getFormValue())
log.error("---------------- Module Owner---------------"+formSubcomponent.getFormValue())
log.error("---------------- Release Prime---------------"+Release_Prime.getFormValue())
dropdown.setReadOnly(false)
switch (myValue) {
case "10030" : //Agent
componentValue = "Platform-Support"
relPrimeVal="Server-release"
break
case "10031" : //Automation tool
componentValue = "automation"
relPrimeVal="Server-release"
break
case "-1" :
componentValue = "kmadhu"
relPrimeVal="Server-release"
break
}
formSubcomponent.setFormValue(componentValue)
Release_Prime.setFormValue(relPrimeVal)
dropdown.setReadOnly(true)I am getting the below ERROR in my groovy script written to map the custom field values for Module Owner, Release Prime based on 'subsystem' custom field value updated in a JIRA issue.
Please advice what is wrong in my groovy script ???
2017-02-02 17:19:45,044 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-02-02 17:19:45,044 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INT-2012, actionId: 1, file: <inline script>
java.lang.NullPointerException: Cannot get property 'customfield_10016' on null object
at com.onresolve.jira.groovy.user.FormField.getFormValue(FormField.groovy:145)
at com.onresolve.jira.groovy.user.FormField$getFormValue.call(Unknown Source)
at Script5285.run(Script5285.groovy:13)
at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:156)
at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript$5.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:48)
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate$doScript$4.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction.doScript(CustomScriptFunction.groovy:43)
Manju