Using ScriptRunner Behaviours on Jira Server. I have a drop down field that I'm using where I want the checkbox field to show or hide dependent on the selection as well as update the options for the checkbox and make the checkboxes required or not required. The checkbox options is working, making the checkboxes required works. The hide and show is not working. If I remove the code to set the options, the hide/show works fine. Looking for a little direction here. Thanks in Advance. Note it should hide the policySymbols field when area field is N/A and show it for all other selections.
Areas is the drop down and policySymbols is the checkbox field. I have the script on the areas field.
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def policySymbols = getFieldByName("Policy Symbols")
def area = getFieldByName("Area")
def customField = customFieldManager.getCustomFieldObject(policySymbols.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def areaVal = area.getValue()
if (areaVal == "All") {
def optionsMap = options.findAll {
it.value in ["CL-BP", "CL-CA", "CL-CPP", "CL-CT", "CL-CUP", "CL-DO", "CL-EO", "CL-EPL", "CL-F", "CL-FO", "CL-FUP", "CL-GLA", "CL-IMP", "CL-OE", "CL-SCP", "CL-WCP", "CL-XA", "CL-XMP", "CL-XPP", "PL-AHP", "PL-AR", "PL-DF", "PL-FA", "PL-FP", "PL-GH", "PL-HM", "PL-HO", "PL-IM", "PL-MA", "PL-MC", "PL-MH", "PL-NSA", "PL-PA", "PL-PA3", "PL-PLH", "PL-PPT", "PL-PRH", "PL-SH", "PL-TH"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(true)
policySymbols.setHidden(false)
}
else if (areaVal == "Commercial Lines") {
def optionsMap = options.findAll {
it.value in ["CL-BP", "CL-CA", "CL-CPP", "CL-CT", "CL-CUP", "CL-DO", "CL-EO", "CL-EPL", "CL-F", "CL-FO", "CL-FUP", "CL-GLA", "CL-IMP", "CL-OE", "CL-SCP", "CL-WCP", "CL-XA", "CL-XMP", "CL-XPP"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(true)
policySymbols.setHidden(false)
}
else if (areaVal == "Personal Lines") {
def optionsMap = options.findAll {
it.value in ["PL-AHP", "PL-AR", "PL-DF", "PL-FA", "PL-FP", "PL-GH", "PL-HM", "PL-HO", "PL-IM", "PL-MA", "PL-MC", "PL-MH", "PL-NSA", "PL-PA", "PL-PA3", "PL-PLH", "PL-PPT", "PL-PRH", "PL-SH", "PL-TH"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(true)
policySymbols.setHidden(false)
}
else if (areaVal == "N/A") {
def optionsMap = options.findAll {
it.value in ["N/A"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(false)
policySymbols.setHidden(true)
}
@Scott Boisvert I'm having the same problem. setHidden and setFieldOptions mess up each other. Were you able to find a solution?
@Merielle Impreso I did actually. Though I don't remember what it was I was able to talk our folks out of using those fields so I removed the script.
If I remember correctly though, it had something to do with where the setHidden call was placed in the script. I think by moving it around it fixed it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Scott Boisvert Thank you for responding. I actually find a workaround on this. What I want is that:
However, the setHidden and setFieldOptions messed up. I tried what you suggested and experiment on the positioning of these functions, but in vain. Anyway, what I did is to have a default Category and make it a required field (since it is really required in our form). That way, there is no None option in the Category selection.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe that is how I got around it as well. The field was required and set the default to include all options, then updated the checkboxes as necessary.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Scott Boisvert
Try to add some log messages to detect problem.
And see altlassian-jira.log when you reproduce the case.
It will give you a direction.
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def policySymbols = getFieldByName("Policy Symbols")
def area = getFieldByName("Area")
def customField = customFieldManager.getCustomFieldObject(policySymbols.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def areaVal = area.getValue()
log.error("AreaVal: " + areaVal)
if (areaVal == "All") {
def optionsMap = options.findAll {
it.value in ["CL-BP", "CL-CA", "CL-CPP", "CL-CT", "CL-CUP", "CL-DO", "CL-EO", "CL-EPL", "CL-F", "CL-FO", "CL-FUP", "CL-GLA", "CL-IMP", "CL-OE", "CL-SCP", "CL-WCP", "CL-XA", "CL-XMP", "CL-XPP", "PL-AHP", "PL-AR", "PL-DF", "PL-FA", "PL-FP", "PL-GH", "PL-HM", "PL-HO", "PL-IM", "PL-MA", "PL-MC", "PL-MH", "PL-NSA", "PL-PA", "PL-PA3", "PL-PLH", "PL-PPT", "PL-PRH", "PL-SH", "PL-TH"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(true)
policySymbols.setHidden(false)
}
else if (areaVal == "Commercial Lines") {
def optionsMap = options.findAll {
it.value in ["CL-BP", "CL-CA", "CL-CPP", "CL-CT", "CL-CUP", "CL-DO", "CL-EO", "CL-EPL", "CL-F", "CL-FO", "CL-FUP", "CL-GLA", "CL-IMP", "CL-OE", "CL-SCP", "CL-WCP", "CL-XA", "CL-XMP", "CL-XPP"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(true)
policySymbols.setHidden(false)
}
else if (areaVal == "Personal Lines") {
def optionsMap = options.findAll {
it.value in ["PL-AHP", "PL-AR", "PL-DF", "PL-FA", "PL-FP", "PL-GH", "PL-HM", "PL-HO", "PL-IM", "PL-MA", "PL-MC", "PL-MH", "PL-NSA", "PL-PA", "PL-PA3", "PL-PLH", "PL-PPT", "PL-PRH", "PL-SH", "PL-TH"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(true)
policySymbols.setHidden(false)
}
else if (areaVal == "N/A") {
def optionsMap = options.findAll {
it.value in ["N/A"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
log.error("Ooptions fo N/A: "+ optionsMap.toString())
policySymbols.setFieldOptions(optionsMap)
policySymbols.setRequired(false)
policySymbols.setHidden(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, unfortunately adding the logs didn't produce anything to lead me to think something is wrong with the code. All three actions returned nothing. I found a nicer way to set the checkboxes as well. Still having the same issue though.
log.error ("Set selections to N/A only: " + policySymbols.setFieldOptions(options.findAll {it.value in ["N/A"]}).toString())
log.error("Set Policy Symbol field not Required: " + policySymbols.setRequired(false).toString())
log.error("Hide Policy Symbol Field: " + policySymbols.setHidden(true).toString())
2018-07-12 14:50:10,287 http-nio-8080-exec-6 ERROR boisvers 890x28122x1 1ul55mf 192.168.108.85 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] Set selections to N/A only: Form field ID: customfield_10408, value: 2018-07-12 14:50:10,287 http-nio-8080-exec-6 ERROR boisvers 890x28122x1 1ul55mf 192.168.108.85 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] Set Policy Symbol field not Required: Form field ID: customfield_10408, value: 2018-07-12 14:50:10,288 http-nio-8080-exec-6 ERROR boisvers 890x28122x1 1ul55mf 192.168.108.85 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] Hide Policy Symbol Field: Form field ID: customfield_10408, value:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Logs didn't call anything out that I could see. I did change the setting of the values to something a littler cleaner, but still have the issue with the "setHidden" command not working.
log.error ("Set selections to N/A only: " + policySymbols.setFieldOptions(options.findAll {it.value in ["N/A"]}).toString())
log.error("Set Policy Symbol field not Required: " + policySymbols.setRequired(false).toString())
log.error("Hide Policy Symbol Field: " + policySymbols.setHidden(true).toString())
2018-07-12 14:50:10,287 http-nio-8080-exec-6 ERROR boisvers 890x28122x1 1ul55mf 192.168.108.85 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] Set selections to N/A only: Form field ID: customfield_10408, value: 2018-07-12 14:50:10,287 http-nio-8080-exec-6 ERROR boisvers 890x28122x1 1ul55mf 192.168.108.85 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] Set Policy Symbol field not Required: Form field ID: customfield_10408, value: 2018-07-12 14:50:10,288 http-nio-8080-exec-6 ERROR boisvers 890x28122x1 1ul55mf 192.168.108.85 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] Hide Policy Symbol Field: Form field ID: customfield_10408, value:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks you from 2025. Still useful sniplet!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.