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

Trying to get a field to be hidden or not hidden depending on the selection of a Multi Select List

Aaron Andrade December 16, 2021

**Already asked this question for a Single Select List, that I got to work, but found out we can't change it to a single select and need to make it work for a Multi Select List**

We are trying to make it where a field is hidden on a screen unless one of the two highlighted choices are picked:

image.png

Here is the code that I got to work for the Single Select List in the behaviour Is there anything I can do to make it work for the Multi Select List?:

def apc = getFieldByName("Analysis Provided to Client")
def severity = getFieldById(getFieldChanged())

def selectedOption = severity.getValue() as String

if (severity.getValue() == "No Impact/Task") {
apc.setHidden(true)
}else if(severity.getValue() == "4 - Affects non-critical function (low impact)") {
apc.setHidden(true)
} else if(severity.getValue() == "3 - Affects non-critical function (high impact)") {
apc.setHidden(true)
}else if(severity.getValue() == "N/A"){
apc.setHidden(true)
}else {
apc.setHidden (false)
}

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
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.
December 16, 2021

What I like to do in this case is do something like this:

severity.setHelpText("$severity.value (${severity.value.getClass()})

This way, you'll see what you're working with based on what you select in your severity. I think you'll see an ArrayList of String values.

Then, you can simplify your code quite a bit.

Try this:

def apcVisibleWhenSeverities = [
'1 - Affects critical function (low impact)',
'2 - Affects critical function (high impact)'
]
def severityFld = getFieldById(fieldChanged)
def apcFld = getFieldByName("Analysis Provided to Client")
apcFld.setHidden(!severityFld.value.any{it in apcVisibleWhenSeverities})

 

Aaron Andrade December 17, 2021

Am I supposed to put the first line code in the behaviour with the other code? I tried the code and it did not work for me unfortunately

image.pngimage.png

I am new to the whole behaviour piece of Jira and I am hoping that I didn't miss anything or set it up work.

image.png

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.
December 17, 2021

Here is what I meant with that first lines... just to use some debug information

2021-12-17 09_34_44-Edit Behaviour_ test.png2021-12-17 09_36_15-Create Issue - JIRA Dev.png

This gives me some information about what type of data we get from fld.value.

Then when I convert the script I gave you to work with my situation and fieldnames,

2021-12-17 09_50_31-Edit Behaviour_ test.png

I'm able to show/hide my sprint field accordingly

Shown because I selected "products"

2021-12-17 09_52_56-Create Issue - JIRA Dev.png

Hidden because products or mobile are not selected:

2021-12-17 09_52_21-Create Issue - JIRA Dev.png

What you have should work. Just make sure the spelling of those severities and field names are correctly matched in the code.

Like Aaron Andrade likes this
Aaron Andrade December 17, 2021

Quick question do I want this behviour on the Multi Select List Field or the Analysis Provided to Client Field? 

Aaron Andrade December 17, 2021

Got it to work! It was a simple wording issue that fixed it.

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.
December 17, 2021

Behaviours on a specific field are executed whenever that field is modified. So you'll want this behaviour code on the Severity field so it fires when you change the severity.

TAGS
AUG Leaders

Atlassian Community Events