I've searched all Atlassian Community groovy script suggestions and still could not find what works.
I'm using ScriptRunner Behaviors version 6.40.0 on Jira Server 8.13.8.
I have custom field A that is a single pick radio button with 11 options. If 5 out of 11 were selected, another custom field B should pop up as Required. The other 6 out of 11 options should have custom field B as hidden and not required.
But the script I used doesn't behave as desired.
import com.atlassian.jira.component.ComponentAccessor
def customFieldAID = getFieldByID(getFieldChanged())
def customFieldA = getFieldByName("Custom Field Radio Button")
def customFieldB = getFieldByName("Custom Field Hidden")
def selected = customFieldAID.getValue() as String
def selectCustomField = customFieldManager.getCustomFieldObject(customFieldA.fieldId)
def selectConfig = selectCustomField.getRelevantConfig(issueContext)
def selectOptions = ComponentAccessor.optionsManager.getOptions(selectConfig)
def fiveOptions = selectOptions.findAll { it.value in ['Option 1' || 'Option 2' || 'Option 3' || 'Option 4' || 'Option 5']}
if (fiveOptions == true) {
customFieldB.setHidden(false)
customFieldB.setRequired(true)
} else {
customFieldB.setHidden(true)
customFieldB.setRequired(false)
For some reason, it will not show custom field B at all. I've tried other variations that will only show up for Option 5 and not the rest.
Any suggestions?
Hello @Diana Gorv ,
I think you are overcomplicating it. Have a behaviours linked to the custom field A with this script :
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def customFieldA = getFieldById(getFieldChanged())
def customFieldAValue = customFieldA.getValue()
def customFieldB = getFieldByName("custom field B")
if (customFieldAValue in ["Option 1","Option 2","Option 3","Option 4","Option 5"]){
customFieldB.setHidden(false)
customFieldB.setRequired(true)
}
else {
customFieldB.setHidden(true)
customFieldB.setRequired(false)
}
Thank you! This works perfectly!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.