Skip to content

Instantly share code, notes, and snippets.

@revuel
Created July 25, 2018 15:54
Show Gist options
  • Save revuel/e00b16b7b82366d0b920aa827b0a6ff6 to your computer and use it in GitHub Desktop.
Save revuel/e00b16b7b82366d0b920aa827b0a6ff6 to your computer and use it in GitHub Desktop.
Jira ScriptRunner, get rid of custom field options with unnecesary extra white spaces
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.context.IssueContextImpl;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.customfields.option.*;
CustomFieldManager cFM = ComponentAccessor.getCustomFieldManager();
CustomField cf = cFM.getCustomFieldObject("customfield_XXXXX"); // Place your custom field id here
Issue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("PKEY-XXX"); // place an issue key (that uses that custom field)
IssueContextImpl issueContext = new com.atlassian.jira.issue.context.IssueContextImpl(issue.getProjectId(), issue.getIssueTypeId());
FieldConfig fieldConfig = cf.getRelevantConfig(issueContext);
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
List<Option> options = optionsManager.getOptions(fieldConfig);
// Replace 2+ whitespaces with just one whitespace
for (Option option in options) {
println option.getValue()
option.setValue(option.getValue().replaceAll("\\s\\s+"," "))
println option.getValue()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment