Script Runner Behaviours - Hide/Show based on checkbox selection

Dave Theodore [Coyote Creek Consulting]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 8, 2016

I have the following checkbox field:

Existing Program or Campaign? ( customfield_10209 )

It has two checkboxes: Yes, No

If (and only if) the "Yes" checkbox is selected, I need the following field to appear on the screen:

Campaign or Program Name ( customfield_10208 )

My server side script:

def checkBox = getFieldById("customfield_10209")
def conditionA = getFieldById("customfield_10208")
conditionA.setHidden(true);
if (checkBox.getValue() == "Yes") {
    conditionA.setHidden(false);
}

JIRA Core version 7.1.9

Script Runner version 4.3.6

 

When creating an issue, the "Campaign or Program name" field always appears. If you tick the "No" checkbox, it goes away. If you untick the "No" checkbox it stays away. If you tick the "Yes" checkbox it appears.  I need to make it not appear initially and only when the "Yes" checkbox is ticked.  

Any suggestions are appreciated.

6 answers

1 accepted

1 vote
Answer accepted
JamieA
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.
September 12, 2016

But to answer your question, it seems like for checkboxes the validatior is not firing when the form first loads, as it should.

To work around this you can use an initialiser to set it hidden at first, or just use the configuration options on the field in the behaviour.

 

Richard Duffy September 12, 2018

@JamieA

 

Hi Jamie

I am trying to fix the same issue, the workaround of using the initialiser does work. However i dont want to use this as I have many projects using this screen scheme so therefore the hidden field is shown on there screens!

I would like to use the field configuration to make my custom field hidden and then use the behaviour to show it. But i cannot get this working.

For this example i have the field "Hidden Field" set to hidden in the field configuration. When i choose "SIT" for the field "Environment Name" it does not unhide "Hidden Field"

def cfENV = getFieldByName("Environment Name")
def cfHID = getFieldByName("Hidden Field")

def cfENVVAL = cfENV.getValue()

if (cfENVVAL == "SIT"){
cfHID.setHidden(false)
}else{
cfHID.setHidden(true)
}

 

ps- All this is on the create screen

Can you advise?

Richard Duffy September 12, 2018

@JamieA

Do i need to look at the field configuration and the custom field config for it? If so how do i do that? 

0 votes
Dave Theodore [Coyote Creek Consulting]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 16, 2016

I got it working.  As Jamie suggested, I needed  to hide the field first with an "Initialiser Function,"

Marc Jason Mutuc
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 18, 2017

Please share your code. I'm trying to the the same but based on the component instead.

0 votes
Dave Theodore [Coyote Creek Consulting]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 12, 2016

They don't want the "none" option, and I can't disable that globally. Checkboxes is an easy way to have only "Yes" and "No" and the plan is to use a workflow validator to ensure that only one is selected.

0 votes
JamieA
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.
September 12, 2016

or a single checkbox...

0 votes
JamieA
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.
September 12, 2016

Why don't you use radio buttons? Being able to tick both Yes and No doesn't make any sense.

0 votes
Mark McCormack _Adaptavist_
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.
September 9, 2016

Hi Dave,

Please try the following:

def checkBoxField = getFieldByName('Existing Program or Campaign')
// Get a pointer to the Start Date Field
def conditionField = getFieldByName('Campaign or Program Name')
 
// Get the Select List Field Value
def checkBoxFieldVal = checkBoxField.getValue()
 
// Hide Campaign or Program Name based on checked value
if (checkBoxFieldVal == "Yes"){
   conditionField.setHidden(false)
}else{
   conditionField.setHidden(true)
}

That works for me, so I hope it helps.

Please ensure you have the Campaign or Program Name field in the behaviour set as Optional/Writable/Shown too.

regards, Mark.

Dave Theodore [Coyote Creek Consulting]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2016

Thanks for the script, Mark.  Unfortunately, same behavior.  This is on a create screen, if that matters.  When I click the Create button, both fields are present. If I tick the "No" checkbox, the "Campaign or Program Name" field goes away. If I untick the "No" checkbox, it stays hidden. If I tick the "Yes" checkbox, it appears.

Mark McCormack _Adaptavist_
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.
September 12, 2016

Hi Dave,

Do you have any javascript or any other Behaviours configured that may potentially clash?

Can you try adding log.warn("setting conditionField") to your logs and see if that helps you get to the bottom of it?

regards, Mark.

Suggest an answer

Log in or Sign up to answer