Forked from revuel/jiracustomfieldoptstrim.groovy
Last active
February 24, 2021 07:02
-
-
Save infernalsirius/932d353493960168f57189bff67d1cd2 to your computer and use it in GitHub Desktop.
[Jira ScriptRunner] Remove extra white spaces in custom field's options. #atlassian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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