Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,800
Community Members
 
Community Events
168
Community Groups

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

Atlassian Community Events