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

Make cascading list mandatory based on another cascading list

Edited

Hi,

I think this can be achieved with behaviors but I am struggling with the code.

I am trying to make "Cascading list 2" mandatory when an option is picked from "Cascading list 1"

Eg:

- On "Cascading list 1" if a user picks option "A" then they have to also fill out "Cascading list 2"

- If they pick option "B" on "Cascading list 1" then "Cascading list 2" is not required.

 

This is some of the code I was playing around with:

 

def fieldA = getFieldByName('BI Reporting & Analytics Request Categories') //this is cascading list 1

def fieldC = getFieldByName('Reporting') //this is the cascading list 2

 

def fieldAValuesThatTriggerFieldCRequired = ['Reporting'] //this is the option choosen in cascading list 1

def valueA = fieldA.value

 

def fieldCIsRequired = valueA in fieldAValuesThatTriggerFieldCRequired

fieldC.setRequired(fieldCIsRequired)

Any assistance is appreciated.

Thanks.

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 10, 2022

You weren't too far off.

Cascading selects return an ArrayList or String values for the selected option. The first item in the list is the first element in the cascade, and the second item in the list would be the second element.

But with behaviour, you can only fire a script when the first element changes. Changing the second element doesn't fire the script. So that second element will only ever be available in scripts triggered from other fields after you've selected both elements of the cascade.

So because the value is a list, you have to extract the first element (the only one with an available value)

Try this version:

def fieldA = getFieldByName('BI Reporting & Analytics Request Categories') //this is cascading list 1
def fieldC = getFieldByName('Reporting') //this is the cascading list 2

def fieldAValuesThatTriggerFieldCRequired = ['Reporting'] //this is the option choosen in cascading list 1

def fieldCIsRequired = false

if(fieldA.value){
fieldCIsRequired = (fieldA.value as List<String>).first() in fieldAValuesThatTriggerFieldCRequired
}
fieldC.setRequired(fieldCIsRequired)

I added a check to make sure a value was selected

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events