Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

formField.setFieldOptions(Iterable) Not working

Hi, 

I have a behavior which is supposed to limit the drop down options a user see's if he inputs a value into a earlier option. 

For example if FieldA =AnswerA Then FieldB (which is a dropdown with many options) should only display A or B to the user as options. 

My code looks like: 

 

import com.atlassian.jira.component.ComponentAccessor



def FieldA = getFieldById("customfield_10001")
def FieldB = getFieldById("customfield_10002")



if (FieldA.getValue() == "AnswerA") {

FieldB.setFieldOptions( ['A', 'B'])

}

These are custom fields and are being accessed correctly as I can use setHidden(true/false) to confirm my If statement can hide and show FieldB based on FieldA's input.

 

What isnt working is the setFieldOptions() method. oddly in the Example on the Behaviours page it actually shows it as: 

formField.setFormValue(options.findAll {it.value in ['foo', 'bar']})

 

When I try and do 

FieldB.setFormValue(options.findAll {it.value in ['A', 'B']})

I get an error message telling me the variable options is undeclared and that there is no such property as it.value

I have tried a lot of random things using code snippets on the answers here but I wonder if the code syntax has changed recently as stuff that people seem to say has worked is giving me error messages. 

 

in short: Would really appreciate if someone could give any advice on how I can limit the selectable options in the drop down. 

 

2 answers

For anyone that finds this, I actually found the answer here: 

https://scriptrunner.adaptavist.com/5.0.2/jira/recipes/behaviours/setting-default-fields.html#_setting_defaults_for_selects_etc

 

There is a lot of component accessor code I needed to make use of options.find and it.value

All the best, 

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.
Nov 03, 2017

Instead of developing a solution use cascade select custom field. It would be much cleaner solution. 

Unfortunately a cascade wouldn't work in this scenario as the fields are relatively unrelated. In a few small cases the first field should limit what the second fields options should be but thats about it. 

As I am not far off the solution it would be really useful to try and understand how the setFieldOptions() method works, unfortunately its not very clear but it would be useful to understand.

Like Rolf Lader likes this
Rolf Lader
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 14, 2023

@Bobhave you ever found a solution to the given problem?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events