Here at Isos Technology, we've seen use cases for pretty much everything. One use case that has come up repeatedly, for both my clients and myself as an admin, has been bulk disabling custom field values. Say you have a select list field with dozens of values and half of them have gone out of commission, or you have a field that had 200 values but you want to replace it with four. This obviously would be painful to do manually one by one. So, in this blog post, I will show you how to quickly bulk disable custom field values using a simple Groovy script! To run it, just pull up the Groovy console in Jira.
Let's jump right in:
As you can see from lines 4-6, we first reference an issue that uses the proper context for the custom field we want to update. We do this since select list custom fields can have various contexts with different sets of options/values. Once we get that proper context, we can proceed to define the values we want to disable, which we do in line 10. Next, we get the custom field object and the custom field options/values so that we can alter the custom field configuration (its options). Finally, in lines 19-26 we go through the options of the custom field and disable the ones we want to disable (as defined in our array in line 10).
Note that in the above script you will need to replace three values:
- The optionsToDisable array - define which values you want to be disabled (line 10)
- The custom field id for the field you are wanting to update (line 8)
- An issue that uses the proper context for the custom field we want to update (line 5)
Now, for the use case of disabling ALL options for a custom field, all you need to do is modify the above script slightly to remove the 'if statement' block, which would look like the below script:
Voila! It is as simple as that! I hope these script snippets can help speed your admin tasks or client needs along. And as always, happy automating!