I have created the below ScriptRunner behaviour, which is functioning, but is also giving an inline error "cannot find matching method getAt(int)". This inline error is filling up the server error logs and cannot be the long term solution. Any input would be greatly appreciated, as at this time I have 3 additional behaviours to create, that are based off of the same input fields.
def fieldToRequire = getFieldByName("Business Area Reporter")
def system = getFieldByName("System Selection").getValue()
if (system[0] == 'Department Name Here') {
fieldToRequire.setRequired(true) //require field
} else {
fieldToRequire.setRequired(false) //do not require
}
Hello,
Try to write it like this:
def fieldToRequire = getFieldByName("Business Area Reporter")
def system = getFieldByName("System Selection").getValue()
if (system.get(0) == 'Department Name Here') {
fieldToRequire.setRequired(true) //require field
} else {
fieldToRequire.setRequired(false) //do not require
}
Alexey,
Thanks for the response, however that does not work either. It gives the same error, "cannot find matching method getAt(int)".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, I see. Could you write the script like this:
def fieldToRequire = getFieldByName("Business Area Reporter")
def system = getFieldByName("System Selection").getValue()
log.error("system class: ${system.getClass()}")
if (system == 'Department Name Here') {
fieldToRequire.setRequired(true) //require field
} else {
fieldToRequire.setRequired(false) //do not require
}
Then have a look at the log message in the atlassian-jira.log file. I guess the system variable is not of List type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alexey,
You are correct, it is an array type, hence why I was looking at it as system[0]. It is not an integer value.
2018-06-26 11:58:29,135 http-nio-8080-exec-25 ERROR brandon-b 718x428556x1 1f8pa07 172.17.210.251 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] system class: class java.util.ArrayList 2018-06-26 11:58:31,766 http-nio-8080-exec-42 ERROR brandon-b 718x428558x1 1f8pa07 172.17.210.251 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] system class: class java.util.ArrayList
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def fieldToRequire = getFieldByName("Business Area Reporter")
def system = getFieldByName("System Selection")?.getValue()
if (system[0] == 'Department Name Here') {
fieldToRequire.setRequired(true) //require field
} else {
fieldToRequire.setRequired(false) //do not require
}
Adding the ? in the def for system corrected the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you mean that your script works now? That would be odd. Because the ? signs just means that if the System Selection field is not found, then the system variable will be equal to null.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My script was always functioning, however it was triggering an error for "java.lang.NullPointerException: Cannot invoke method getAt() on null objectCannot invoke method getAt() on null object". Now it is functioning, and no longer triggering a log error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got it. That is right. You did it!
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.