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

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,552,584
Community Members
 
Community Events
184
Community Groups

How do I validate multiple components in a script?

I have a behaviours script that will hide options in a multi-select field based upon what component is selected. 

 

My question is can I generate a map of options if two components or more are selected? (the third else if statement is my attempt ;( )

Below is the part of the code I need help on:

if (componentImpl?.getName()?.equals("component1")) {
def optionsMap = options.findAll {
it.value in ["option4","option6"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}


else if (componentImpl?.getName()?.equals("Component2")) {
def optionsMap = options.findAll {
it.value in ["option1","option2","option3","option4"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}

else if ((componentImpl?.getName()?.equals("Component2")) && (componentImpl?.getName()?.equals("component1"))){
def optionsMap = options.findAll {
it.value in ["option1","option2","option3","option4","option4","option6"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}

 

1 answer

3 votes
Kyle Moseley
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.
Feb 07, 2018

Try this logic on the last else if: componentImpl?.size()>1

This is assuming that the componentImpl holds the actual value of the Component System Field as an array.

 

 

What if you have more than 2 components and they have different options in the select list? The example would definitely work for two components, but not sure it would work with more than 2.

Kyle Moseley
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.
Feb 07, 2018

I would create multiple Lists (groovy object) to solve this. The first would be a cumulative List of options that will ultimately be rendered.

The other Lists would be options for each Component -- assuming they all could bring in different available options. Then, I would iterate through each Component entity value and use a Switch Statement to add the Component's option List if applicable to my cumulative List. At the end, toss out duplicates from your cumulative List. And eventually that cumulative List as my options to be displayed. 

Good idea! I’ll give it a try and report back. 

Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events