Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Bulk Delete Custom Fields According to the Field Name

Created 1 year ago, Updated 1 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.22 - 9.4)
compatibility bullet
ScriptRunner For Jira (7.7.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager
def customFieldObjects = customFieldManager.customFieldObjects

/*
Specify the starting characters for the names of the custom fields that you intend to remove
For example, if the value is set to Test, then all the custom fields that begin with the name Test will be included
into the list and removed
 */
final def custom_field_name_starts_with = '<STARTING_CHARACTERS_IN_CUSTOM_FIELD_NAME>'

def filteredField = customFieldObjects.collect {
    if (it.name.startsWith(custom_field_name_starts_with)) {
        it.name
    }
}.findResults { it } //This is to remove all null values from the List

filteredField.each {
    def field = customFieldManager.getCustomFieldObjectsByName(it).first()
    customFieldManager.removeCustomField(field)
}
Having an issue with this script?
Report it here