Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner behaviour write a script to hide field

Diana Scalzo September 23, 2022

I'd like to hide a field based on another field's value. if summary's value contains 'XYZ', then hide, otherwise not hide. I'm not sure how to express field contains xxx keywords in script and my script now is like below.

However, even if summary equals exactly XYZ, this code still doesn't work when I edit the issue. Anyone can give a hint or revise for this?

 

def customField = getFieldByName("custom1")
def hidefield = getFieldByName("Summary")
customField.setHidden(false)

// check to see which screen you are on
if ( hidefield == "XYZ") {
    // hide field during issue creation
    customField.setHidden(true)
}

1 answer

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2022

You're declaring the 'hidefield' via getFieldByName("xx"), which returns you the field - and then you are trying to do an equals comparison on it, by string, i.e. field == "XYZ". So those are 2 different object types.

 

See the API documentation on how to get the value from the field:

 # https://docs.adaptavist.com/sr4js/7.0.0/features/behaviours/api-quick-reference?utm_source=product-help

 

Which should be hidefield.getValue() and as that is Summary, that should return String, in which case equals/== will work, or you can use .contains("XYZ").

Suggest an answer

Log in or Sign up to answer