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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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 Marketplace Apps & Integrations

Happy New Year and Welcome New Marketplace Partner Program Partners!

Happy New Year! We hope you all had a safe and restful holiday season. 2020 was a unique year full of unforeseen events; however, as we enter the new year of 2021, we’re optimistic for the light at t...

536 views 7 20
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