Forums

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

Hide fields based on checkbox select

Krithica Gowri Shankar
Contributor
June 4, 2018

 

Hi,

I have a check box field with 5 values A, B, C, D, E.

Aldo 5 text fields Field1, Field2, .. Field5.

If Option A is checked - Field1 should be visible and other fields should be hidden.

If Option B is checked - Field2 should be visible and other fields should be hidden.

If Option C is checked - Field3 should be visible and other fields should be hidden.

Likewise for other options.

Using behaviour works perfectly when only 1 option is checked.

Now that if i choose Options A and B i want fields 1 and 2 to be visible and other fields to be hidden. And if i choose all options all fields to be displayed. This does not work. How to achieve this? Kindly help.

Thanks,

Krithica

1 answer

0 votes
Alexey Matveev
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.
June 4, 2018

Hello,

It should work with behaviours. Could you provide your script?

Krithica Gowri Shankar
Contributor
June 4, 2018

Here is the script.

"

def Checkbox = getFieldById("Checkbox")
def 1= getFieldById("Field1")
def 2= getFieldById("Field2")
def 3= getFieldById("Field3")
def 4= getFieldById("Field4")
def 5= getFieldById("Field5")
log.debug("Checkbox " + CheckboxgetValue())

if (Checkbox.getValue() == "A"){
1.setHidden(false);
2.setHidden(true);
3.setHidden(true);
4.setHidden(true);
5.setHidden(true);
1.setRequired(true);
2.setRequired(false);
3.setRequired(false);
4.setRequired(false);
5.setRequired(false);
}

else if (Checkbox .getValue() == "B") {
1.setHidden(true);
2.setHidden(false);
3.setHidden(true);
4.setHidden(true);
5.setHidden(true);
1.setRequired(false);
2.setRequired(true);
3.setRequired(false);
4.setRequired(false);
5.setRequired(false);
}
else if(Checkbox .getValue() == "C"){
1.setHidden(true);
2.setHidden(true);
3.setHidden(false);
4.setHidden(true);
5.setHidden(true);
1.setRequired(false);
2.setRequired(false);
3.setRequired(true);
4.setRequired(false);
5.setRequired(false);
}
else if(Checkbox .getValue() == "D"){
1.setHidden(true);
2.setHidden(true);
3.setHidden(true);
4.setHidden(true);
5.setHidden(false);
1.setRequired(false);
2.setRequired(false);
3.setRequired(false);
4.setRequired(false);
5.setRequired(true);
}
else if(Checkbox .getValue() == "E"){
1.setHidden(true);
2.setHidden(true);
3.setHidden(true);
4.setHidden(false);
5.setHidden(true);
1.setRequired(false);
2.setRequired(false);
3.setRequired(false);
4.setRequired(true);
5.setRequired(false);
}
else
{
1.setHidden(true);
2.setHidden(true);
3.setHidden(true);
4.setHidden(true);
5.setHidden(true);
1.setRequired(false);
2.setRequired(false);
3.setRequired(false);
4.setRequired(false);
5.setRequired(false);
}

"

Kindly check and let me know what changes are needed to the script 

Thanks,

Krithica

Alexey Matveev
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.
June 4, 2018

I would write it like this:

if (Checkbox.getValue().find{it.toString().equals("A")})

Krithica Gowri Shankar
Contributor
June 4, 2018

Thanks for the help.

I used .contains instead of == it works now.

Tanu
Contributor
April 6, 2020

@Krithica Gowri Shankar 

Can you help me with small snapshot of your code ?
As mine is not working , in my create scree i see all the fields regardless of my code.

Tanu
Contributor
April 6, 2020

Also, wanted to mention, the fields which i am trying to hide based on check box options are multiselect field..

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events