Make required field due to an other. Behavior

Boris Demain July 24, 2019

Hi, 

I would have a required field (RespoTRA) when other field (DetectEnviro) have specific value : "Production"

I use this script with script runner (in behavior).

import com.atlassian.jira.component.ComponentAccessor

def DetectEnviro = getFieldById("customfield_10232")
def RespoTRA = getFieldById("customfield_10248")

if (DetectEnviro.getValue() == "Production") {
RespoTRA.setRequired(true)
}
else {
RespoTRA.setRequired(false)
}

That works but not all time. 
When I open eddit screen, if the value is Production, I can validate even if RespoTRA is empty. The second time it's work.

And if I change the value of DetectEnviro (with other than Production), RespoTRA stay required while it should not. If I look in list of RespoTRA the required disappears.

I didn't manage to use initializer...

Can someone help me ?

1 answer

1 accepted

0 votes
Answer accepted
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.
July 24, 2019

Hi @Boris Demain ,

The script looks fine ; you should use it in the initializer and also bind it with the DetectEnviro field.

If that does not work, check the logs and maybe add 

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

Antoine

Boris Demain July 24, 2019

Thank you so much !

My mistake was to bind with wrong field the script.

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer