Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script to find exactly one value from multi-select field ?

Priyanka Nimbalkar May 7, 2020

Hi Team,

I want to write groovy script where user selects options from lets say MULTI -SELECT field

" Environment."

So if users selects ONLY one  option "Testing" (just example) for Environment  then another field called " Date" should get hidden.

I can work on the part to hide the field but i am unable to get the option when chosen by user , as the multi select field returns array of values and this should be executed only when  single option is selected i.e "testing".

 

Tried this but couldn't apply the logic : 

def selectList = getFieldByName("Environment")

def textField = getFieldByName("Date")


def selectedOption = selectList.getValue() as String

if (selectedOption.contains("testing"))
if("testing" in selectedOption)
{
textField.setHidden(true)

}
else
{
textField.setHidden(false)

}

Regards,

Priyanka Nimbalkar.

1 answer

0 votes
Lasse Langhorn
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.
May 8, 2020

Hi @Priyanka Nimbalkar

What about something like this:

def dateField = getFieldByName("Date")
def environmentField = getFieldById(getFieldChanged())

def selectedOption = environmentField?.getValue() as String
def isTestingSelected = (selectedOption == "Testing")

dateField?.setHidden(!isTestingSelected)

Regards

Lasse Langhorn

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events