How to add behaviour


I’m trying to add a behaviour that should make the field “Impediment reason” mandatory, when “Flagged” is selected.

I’m trying with this:

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

FormField flaggedField = getFieldByName(“Flagged”)
FormField reasonField = getFieldByName(“Impediment Reason”)

def flagged = flaggedField.getValue()

if(flagged.toString() == ‘1’)

But nothing seems to happen. I don’t get any errors, so I’m not even sure if I added it correctly. I went to behaviours, select “add new”, then I clicked on fields, and added an initialiser, where I put the above code. Then I mapped it to all projects and all issue types.

Please let me know what I’m doing wrong.

Thank you.

That’s never going to work. Log the output of flagged.toString() and see what value it has; the comparison is likely always failing, i.e. always false.