Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Previously working ScriptRunner Cloud script now getting null value error

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"""

1 answer

1 accepted

0 votes
Answer accepted

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.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

159 views 3 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you