I am using a customer notification script on a transition. It has worked without issue many times with any/all of the fields in the script being null, but now I'm getting null exceptions.
Has there been any change to the rules?
Here is my error:
Error: java.lang.RuntimeException: java.lang.NullPointerException: Cannot get property 'fields' on null object at Script2.run(Script2.groovy:6) at Script2$run.call(Unknown Source) at Script1$run.call(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:33) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at com.adaptavist.sr.cloud.workflow.SendNotification.run(SendNotification.groovy:115)
Here is the script that has previously worked flawlessly, but doesn't run at all now. As a side note, this script WILL work correctly in the Script console.
def issue = get("/rest/api/2/issue/")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
def fields = issue.fields as Map
def customField1 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Application (s)'
} as Map
def values1 = fields[customField1.id] as List<Map>
def fieldValues1 = values1.collect {
it.value
}
//returns the value for Vendors - aka - checkbox
def customField2 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Vendor(s)'
} as Map
def checkboxValues = fields[customField2.id] as List<Map>
def checkboxFieldValues = checkboxValues.collect {
it.value
}
//returns the value for PrimaryDomain - aka - single select list
def customField3 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Primary Domain'
} as Map
assert customField3 : "Failed to find custom field with given name"
def value3 = (fields[customField3.id] as Map)?.value
//returns the value for business requirements
def customField4 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Business Requirements'
} as Map
assert customField4 : "Failed to find custom field with given name"
def value4 = (fields[customField4.id] as String)
//returns the value for multi-select - aka fixversion
String fixV = get("/rest/api/2/issue/${issue.key}") //change this from issue.key to issuekey to run in script console
.asObject(Map)
.body['fields']['fixVersions']['name']
def fixVer = fixV.replaceAll("\\[|\\]","")
//returns the value for Lead IT BA - aka - single select list
def customField6 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Lead IT BA'
} as Map
assert customField6 : "Failed to find custom field with given name"
def value6 = (fields[customField6.id] as Map)?.displayName
"""The request <b> ${issue.key}</b>, requires an initial estimate by <b>${return checkboxFieldValues}}</b>.
<br>
<br>
<b> Lead IT BA:</B> ${return value6}
<br>
<br>
<b> FixVersion:</B> ${return fixVer}
<br>
<br>
<b>Primary Domain</b>: ${return value3}
<br>
<br>
<b>Applications</b>: ${return fieldValues1}
<br>
<br>
<b>Business Requirements</b>: ${return value4}
<br>
<br>
Regards,
<br>JIRA Team"""
Hi Matt,
Thank you for your question.
Can I please are you running this script as a workflow post function.
If so i can confirm the first rest call you have to get the issue will be invalid and this can be removed as postfunctions already have the issue object in the binding so you can simly call issue.fields and then then the name of a field to access the field directly in the script such as issue.fields.customfield_12345.
Can I ask you to remove this rest call in lines 1-5 and then to confirm if this resolves the issue which you are seeing as this rest call will always return null inside of a post function.
Regards,
Kristian
Thanks @Kristian Walker _Adaptavist_ ! I swore I already tried that this morning - maybe I didn't publish that version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.