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

Scriptrunner Behaviour to require and unhide a field based on value of another field

Bethany Glismann June 10, 2019

Hello!

 

I'm trying to implement a Behavior using Scriptrunner. I have a field for Severity that is required on a specific Service Desk request. Desired behavior is that if a user selects "High" value for Severity, a field (previously hidden) will appear for Emergency Justification, and this field will be required. 

I modeled my code after the solution I found on this question, but it isn't working. Here's the code:

 

import com.atlassian.jira.issue.fields.CustomField

def CustomField = getFieldById("customfield_10408")
def Custom2Field = getFieldById("customfield_10622")

if (CustomField.getValue() == "High (Emergency)") {
Custom2Field.setRequired(true)
Custom2Field.setHidden(false)

}
else {
Custom2Field.setRequired(false)
Custom2Field.setHidden(true)

}

 

It appears to work partially, because customfield_10622 is set in the screen as not hidden, and it is hidden to the user when initially entering the Request. But it doesn't appear when the defined value is selected. What am I missing?

*using Jira 8.1 + Scriptrunner 5.5.6.1-jira8

 

3 answers

2 accepted

1 vote
Answer accepted
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 10, 2019

Hi @Bethany Glismann 

 

Can you paste a screenshot of behaviours configuration?

In my cases when behaviours didn't work the reason was in wrong place where I put script.

 

Regards,

Seba

Bethany Glismann June 11, 2019

Hi Seba,

Thanks for the reply. You may be right - the screenshots I used from the how-tos were for an older version and didn't look like my version, so maybe I put it in the wrong place. See screenshot.

Thanks,

2019-06-11_10-22-36.png

0 votes
Answer accepted
Bethany Glismann June 12, 2019

Sorry @Sebastian Krzewiński I tried to respond yesterday and the community seemed to be down. Adaptavist support got back to me and indeed, I was using the wrong area for my script (entering it in the Initializer area, not the server-side script area). All good now!

0 votes
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 11, 2019

Hi @Bethany Glismann ,

What do the logs say ? You should log the value to make sure it is consistent to the String you are testing against :

log.error("CustomField value : " + CustomField.getValue())

 Antoine

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events