Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,265
Community Members
 
Community Events
168
Community Groups

Set a field as required based on another custom cascade select list field

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. 

  • Business Area Reporter is a custom field list box
  • System Selection is a cascaded list box, with the first list being a department name, and the second list being a selection of system for each specific department.
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
}

 

1 answer

0 votes

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

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. 

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

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.

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.

I got it. That is right. You did it!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

190 views 1 6
Read article

Atlassian Community Events