Missed Team ’24? Catch up on announcements here.

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

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

Brandon Buckner June 25, 2018

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

Suggest an answer

Log in or Sign up to answer
0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 25, 2018

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
}
Brandon Buckner June 26, 2018

Alexey,

Thanks for the response, however that does not work either. It gives the same error, "cannot find matching method getAt(int)".

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

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. 

Brandon Buckner June 26, 2018

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
Brandon Buckner July 6, 2018
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.  

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2018

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.

Brandon Buckner July 6, 2018

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.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2018

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

TAGS
AUG Leaders

Atlassian Community Events