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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Behaviour : Checking 'None' option , all other checked options should be unchecked Edited

Hi,

I have created a 'multi select checkboxes' custom field 5 option including 'None'.

It is a single field with multiple checkboxes as options.

 Screen Shot 2018-10-09 at 7.39.00 PM.png

 

I am trying to write a behaviour script for that field such way that if 'None' option is checked, then all other selected option will be unchecked by automatically. Also, 'None' will be unchecked by selecting any other option.

 

Here is my code,

def gatingMechanismField = getFieldById(getFieldChanged()) // Getting Gating Mechanism field object
def gatingMechanismValue = gatingMechanismField.getFormValue(); // Getting gating mechanism values


if(gatingMechanismValue == '13405' )
{
gatingMechanismField.setFormValue('13405')
}
else
{
List list = gatingMechanismValue;

if(list.contains(13405))
{
list.remove(13405);
gatingMechanismField.setFormValue(list)
}
}

 

It doesn't work. 

Observation: 

- getFormValue() return's value of the option (say: 13405) as a string when 'None' is chosen

- If we choose more than one option , it returns array list (ex: [13405, 13400. 13401])

 

 

Can someone please help me on this.

 

 

1 answer

Hi Nallu.

I've done some minor modifications to your code, where you had a few dangerous statements that could lead to exceptions. Also, if I'm not mistaken, the value isn't a long, it's a String.

Try this:

def gatingMechanismField = getFieldById(getFieldChanged()) // Getting Gating Mechanism field object
def gatingMechanismValue = gatingMechanismField.getFormValue() // Getting gating mechanism values

if(gatingMechanismValue instanceof List) {
def list = gatingMechanismValue as List
if(list.contains('13405')) {
list.remove('13405')
gatingMechanismField.setFormValue(list)
}
} else {
gatingMechanismField.setFormValue(['13405'])
}

Cheers:

DYelamos

Btw I could be wrong about the ids being strings, if I am wrong, substitute all of the 

'13405'

for

13405

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

162 views 1 1
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you