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

With Scriptrunner Behaviour - hide a field based on the values of a cascading field

Hi all,

 

I want to hide customfield_31613 when the values of the cascading field customfield_32216 are "a" and "b" (parent value and child value) respectively.

I'm using Behaviours for it, my current code:

def listField = getFieldById("customfield_32216")
def hiddenField = getFieldById("customfield_31613")

// get cascading list value (parent and child)
String listString = listField.getValue()
// if cascading list matches one of two selections, hide the Due Date OPS field
if ( listString == ["a", "b"]) {
hiddenField.setHidden(true)
}

 

It doesn't work. Can you tell me where I did wrong?

 

Thank you,

Duong

1 answer

1 accepted

Hi @anarcon GmbH,

If you wanted to hide a field based on a cascade list value using behaviour, you could try this script to hide the field:

//get the custom field details
def customField = getFieldByName("Cascade1")
def custField = getFieldByName("Select1")
//get the cascade field value
def cfAValue = customField.value as List

//for debug purpose
log.warn "cfAValue: " + cfAValue

if (cfAValue) {

//Size at least 2 [parentValue, childValue]
if (cfAValue.size()>1) {
//The 1st value will be your parent value, and the 2nd value will be your child value:
def parentValue = cfAValue.get(0)
def childValue = cfAValue.get(1)

//For debug purpose
log.warn "cfAValue: ${cfAValue}"
log.warn "parentValue: ${parentValue}"
log.warn "childValue: ${childValue}"

if(parentValue == "A" && childValue == "B"){
custField.setHidden(true)
} else {
custField.setHidden(false)
}
}
}

 I hope this able to help you with your requirement.

Hi @Amir Mustapha _Adaptavist_ ,

 

Thank you for your answer, it worked!

One problem though: when we change the cascade field values back to empty while creating the issues, the hidden field doesn't show up again. Do you know how to fix this?

Hi @anarcon GmbH,

From the sample script provided, if it meets the condition, you will setHidden(true) else you should also set the value to setHidden(false) from this sample condition to make the field reappear:

if(parentValue == "A" && childValue == "B"){
custField.setHidden(true)
} else {
custField.setHidden(false)
}

 I hope this able to answer.

Like Bridy Frett likes this

Thank you for the sample code - it works great!

One additional question.  I notice when the create screen is initially displayed, custField is visible.  Once I select the first part of the cascading field, the custField becomes hidden.  It's not visible again until the user selects the matching criteria.

How can I make the field hidden on create ... hidden until the user selects the matching criteria to make the field hidden.

Thanks!

Bridy

I figured it out right after the post, of course!

I made the following adjustment

if (cfAValue) {

   ... same code as above

} else {
custField.setHidden(true)
}

Suggest an answer

Log in or Sign up to answer
TAGS

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