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

Hiding field using behaviour

Hi Team,

I want hide a text field depending on the value of select list field. written a below script but not getting expected output.

Can you please check and let me know where I am wrong:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

def textField = getFieldById("customfield_22695")
def selectList = getFieldById("customfield_22694")

def selectListValue = selectList.getValue()

if (selectListValue == "None")
{
textField.setHidden(true)
}
else
{
textField.setHidden(false)
}

1 answer

1 accepted

1 vote
Answer accepted

Hi

NONE is not an actual value for the select list. It's only a place holder when no values are selected.

So you can do a simple groovy truthy check like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

def textField = getFieldById("customfield_22695")
def selectList = getFieldById("customfield_22694")

def selectListValue = selectList.value

if (selectListValue){
textField.setHidden(true)
} else {
textField.setHidden(false)
}

Thanks Peter,

It worked, thanks once again.

Regards,

Neeta Jain

Hi Peter,

If I want to modify my script to hide the field for the options called None and No.

The field should be visible for the value Yes, Can you check my below script is ok or need some modification:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

def textField = getFieldById("customfield_22695")
def selectList = getFieldById("customfield_22694")

def selectListValue = selectList.value

if (selectListValue == "None" || selectListValue == "No")
{
textField.setHidden(true)
}
else
{
textField.setHidden(false)
}

 

The above script is working for Yes and No value,, but not for None, kindly suggest teh correction.

 

Regards,

Neeta Jain

One of these should work:

if (!selectListValue || selectListValue == "No")
if (selectListValue == '' || selectListValue == "No")

Thanks Peter..

Second one worked.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

555 views 15 18
Read article

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