How do you update issues after a select list option is renamed programmatically?

I have a script that gets fired on issueupdated/issuedeleted events and renames options configured in a single-select custom field.

The renaming part is working fine, however when I look at issues using the renamed option, on the "view" screen they are still showing the old value. If I go into "edit" mode the new option value is displayed (and is correctly selected as the current value for that issue).

Things I've tried:

  • Perform a full re-index.
  • Restart the JIRA service.
  • Extending the script to get a list of afffected issues and explicitly updating the field value.
  • Extending the script to get a list of affected issues and reindex them one by one.

Is there an extra step that needs to be performed to let issues know that the option has been renamed so they display the correct value? Here's a snippet of the code I'm using (including my attempts to get the issue to recognise the new value):

CustomField customField = this.customFieldManager.getCustomFieldObject(CUSTOMFIELD_ID);

FieldConfig fieldConfig = customField.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig();

Options fieldOptions = this.optionsManager.getOptions(fieldConfig);

Option existingOption = fieldOptions.getOptionForValue(originalValue, null);

if (existingOption) {
    existingOption.setValue(newValue);

    // later that evening...

    List<Issue> issues = searchResults.getIssues();

    if (issues) {
        fieldOptions = this.optionsManager.getOptions(fieldConfig);

        existingOption = fieldOptions.getOptionForValue(newValue, null);

        IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();

        for (Issue existingIssue : issues) {
            // Update the new issues with the renamed option
            customField.updateValue(null, existingIssue, new ModifiedValue(customField.getValue(existingIssue), existingOption), changeHolder);
        
        this.issueManager.updateIssue(this.currentUser.getDirectoryUser(), existingIssue, EventDispatchOption.ISSUE_UPDATED, false);

// Explicitly reindex the issues
ComponentAccessor.getIssueIndexManager().reIndex(existingIssue);
        }
    }
}

2 answers

1 accepted

It's not ideal but I found a work-around. Instead of renaming an existing option, I just create a new one, point any issues using the old option to the new option, reindex them then delete the old option. It works but feels like a bit of a dirty hack...

If it helps at all I'm using JIRA 6.2.1 and Script Runner 2.1.17 (doesn't officially support 6.2.x but I haven't had any show-stopper compatibility problems so far)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

765 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you