Restore labels in Jira issue

Rinaldi James Michael
Contributor
December 16, 2024

I've run an automation rule over a month ago and have now noticed that the labels were replaced by default instead of being appended to the existing values. Is there a way to append the previous value to the issues now?

Either through ScriptRunner or Automation?

2 answers

1 vote
Bobby Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2024

Hi @Rinaldi James Michael ,

What you need is possible, but I am afraid I don't have the full code here. I can point you in the right direction. 

You can get the change history for a Jira issue in DC like so: 

 

import com.atlassian.jira.component.ComponentAccessor

Issues.search('project = WEB').each{ issue ->
        def changeHistory = ComponentAccessor.changeHistoryManager.getChangeHistories(issue)

        changeHistory.forEach{ changeItem ->
          log.error(changeItem.authorDisplayName)
            log.error(changeItem.changeItems.toString())
        }
    }


So, you will need to write code to go through all changeItems, check to see if the author was Automation. If it was, check to see if there is a change item for field Labels, and if so, if there is anything listed in the oldValue that was not in the newValue (I.E removed).

You would then need to gather all of these values, and append them onto the label field for that issue. 

Does this help?

Kind regards, 

Bobby

0 votes
Aaron Pavez _ServiceRocket_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 16, 2024

Hi @Rinaldi James Michael 

If you know which labels were removed, you can bulk-update those issues and add the right labels.

You need to add both/several at the same time though. Append is not possible. Scriptrunner can do it though.

https://confluence.atlassian.com/jirakb/edit-and-rename-labels-in-jira-cloud-1116305331.html

More on append here:

https://community.atlassian.com/t5/Jira-questions/Is-there-a-way-to-append-multiple-labels-to-an-existing-issue/qaq-p/2147110

Regards

Aaron

Rinaldi James Michael
Contributor
December 16, 2024

Hi @Aaron Pavez _ServiceRocket_

Unfortunately I only know the issues that were modified but they all had different labels.

Is there a Scriptrunner script for Jira Data Center?

Bobby Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2024

Sorry, responded in wrong location

Suggest an answer

Log in or Sign up to answer