IMPORTANT NOTE: This script removes permanently a subset of customfields of your Jira. Before launch this script, we STRONGLY recommend to create a backup (following the Atlassian instructions). MrAddon is not responsible of the bad use of this script, the data removed, or some consequence derived.

This script removes permanently the Jira customfields that start with “_” character.

Remember to create first a backup of the database. Remember to rename the fields of your Jira (pending to be deleted) with an “_” character at the start of the name. Remember to check they not appear in the screens ( we strongly recommend to complete the JiraStrategy tests before start the “Eraser”  operation).

And… the script:

(remember to remove the comment from the line commented 🙂 )

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.fields.*;

def checkFieldToBeDeleted(field) {
	return field.name.startsWith("_")
}

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
Collection customFields = customFieldManager.getCustomFieldObjects();
String names = "";
int counter = 0;
for (CustomField field: customFields) {
	if (checkFieldToBeDeleted(field)) {
        counter++;
        names = names + ", " + counter + ": "+ field.name;
		//customFieldManager.removeCustomField(field);
	}
}
return names;

We recommed to use plugins like Adaptavist Scriptrunner or MyGroovyto launch this.

Very useful script!!

Another tricks:

By MrAddon

Advertisements
Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s