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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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 Statuspage

New feature: Slack notifications for Statuspage

We're excited to announce the release of a long-requested feature on Statuspage. Now visitors to your status page can subscribe to get notified in Slack when you report an incident or maintenance. Th...

67 views 0 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you