How do I add a label as part of the workflow transition?

I am looking for a simple way to label an issue as part of the workflow action.

We are planning to remove the "Reopened" Status, and keep only the Open one but some people do still want to be able to findout if a an issue was reopened.

Extra Kudos if this can be implemented without requiring another plugin.

Note: that's adding a new label, not overriting all existing lables with "reopen" one!

7 answers

1 accepted

3 votes
Accepted answer

Hi Sorin,

You can add a label on transition by writing a post function using script runner plugin.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels({it.getLabel()}
labels += 'labelToBeRemoved'

Hope this helps.


Couldn't this just be:

import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()
def labelManager = ComponentAccessor.getComponent(LabelManager)
labelManager.addLabel(user,, "my-new-label", false)

that is, use addLabel, rather than set all labels.

Also, it's a bit confusing that in your example you're adding a called called: labelToBeRemoved!

Yes Jamie, I agree :)

Problem is with copy paste. I am using the script to remove so i just changed - to + and pasted it here.

Thanks Jamie and Vijay! Jamie, I copied and pasted the code that you have scripted into my instance of JIRA (V6.2.4) but it did not work. I tried the code (simple copy and paste again) that Vijay has scripted and it worked. Even tried the "-" to remove a label and that also worked. I would prefer to use yours as it seems simpler but would like some tips as to why it would not be working. My questions are as follows: a) Do I need to modify it in any way for my application (swap out any variable) and b) to removed a label do I simply change ".addLabel" to ".removeLabel"? c) how would I modify the script if I wanted to write a label to a Label Custom Field? Thanks Frank

try adding: import com.atlassian.jira.issue.label.LabelManager

Has anyone seen this error when adding this script? Error creating issue: root cause: Traceback (most recent call last): File "C:\Program Files\Atlassian\Application Data\JIRA\jss\jython\", line 6, in <module> codecs.setDefaultEncoding('utf-8') LookupError: no codec search functions registered: can't find encoding 'utf-8'

that's an error from jira scripting suite... double-check what plugin you want to use. Use JSS for python, ScriptRunner for groovy.

I am not a programmer so how would that look in JSS?

If you want a JSS answer create a new question and use that plugin's tag.

Why not using simply a filter to identify those reopened issue

status changed from xxx to open

I do find this approach quite interesting but I am afraid that is does not work as expected. I am looking for a way to indetify reopened issues. If the workflow does not have new you cannot do

NOT (status changed from New to Open) and status = Open

If you have any other ideas it would be more than happy to hear them.

So what are the possible 'reopen' transitions? From which status do they start? Lets say you have status Resolved and Closed from where you could reopen your issue, then the filter you use to identify reopened issues would be:

status changed from Resolved to open or status changed from Closed to open

"status changed to Open" - doesn't that work?

Yes, it does - unless there is a transition from open to open.

@Jamie Echlin [Adaptavist], thank you, your code helped me a lot!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Jira

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,096 views 0 8
Read article

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