Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Behaviour script fails

Rob Schalken April 6, 2018

I had the following script in behaviour. This script checks on SW/FPGA label and then enables the setrequired function. This was working fine. But I did an update (have always the latest plugin version, Jira 7.8.1) and now it fails.

 

<code>

def labelsField = getFieldById("labels")
def revisionField = getFieldById("customfield_12307")

try {
 if ((labelsField.getValue().toUpperCase() == "SW") ||
     (labelsField.getValue().toUpperCase() == "FPGA")) {
     revisionField.setRequired(true);
 }
 else {
     revisionField.setRequired(false);
 }
}
catch (ex) {
 if ((labelsField.getValue().toUpperCase().contains("SW")) ||
     (labelsField.getValue().toUpperCase().contains("FPGA"))) {
     revisionField.setRequired(true);
 }
 else {
     revisionField.setRequired(false);
 }    
}

</code>

<error>

at Script1.run(Script1.groovy:16)
java.lang.NullPointerException: Cannot invoke method toUpperCase() on null object
2018-04-06 13:19:23,136 http-nio-8080-exec-10 ERROR ROBS 799x7349x1 81tin3 84.105.226.128,127.0.0.1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: issue: XXX-425, user: ROBS, fieldId: customfield_12307, file: <inline script>
2018-04-06 13:19:23,132 http-nio-8080-exec-10 ERROR ROBS 799x7349x1 81tin3 84.105.226.128,127.0.0.1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl]

</error>

 

Hope you can help me with this.

1 answer

1 vote
Tarun Sapra
Community Champion
April 6, 2018

Hello @Rob Schalken

Could it be that the script is executed on for the issue which has empty labels because in that case it will throw NullPOinterException.

Rob Schalken April 6, 2018

Hello Tarun,

This is not the case. There is a label available.

Rob

Tarun Sapra
Community Champion
April 6, 2018

Can you try "getFieldByName()"

https://scriptrunner.adaptavist.com/5.3.9/jira/behaviours-api-quickref.html

And also since it's labels field then it will be returning a list of values instead of a single value, may be you have to do "list.first()" to get the first value.

Rob Schalken April 6, 2018

Found the problem. The label was not on the screen. So now I added this and it is working now.

Tarun Sapra
Community Champion
April 6, 2018

That's good to know, no wonder it was returning null. As the only reason it can return null is either it's empty(which I was thinking) or it's not on the screen (which is the actual reason). Please accept/upvote if you felt the answer was useful or might help other users.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events