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!

6 answers

1 accepted

This widget could not be displayed.

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(issue.id).collect{it.getLabel()}
labels += 'labelToBeRemoved'
labelManager.setLabels(user,issue.id,labels.toSet(),false,false)

Hope this helps.

Vijay

Couldn't this just be:

import com.atlassian.jira.component.ComponentAccessor
  
def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()
  
def labelManager = ComponentAccessor.getComponent(LabelManager)
labelManager.addLabel(user,issue.id, "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\__init_interpreter__.py", 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.

This widget could not be displayed.

Why not using simply a filter to identify those reopened issue

status changed from xxx to open

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

69 views 0 1
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