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,338
Community Members
 
Community Events
168
Community Groups

ScriptRunner behaviour write a script to hide field

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

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
TAGS

Atlassian Community Events