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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found the problem. The label was not on the screen. So now I added this and it is working now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.