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

Sorin Sbarnea (Citrix)
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.
June 19, 2014

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
Answer accepted
Vijay Khacharia
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.
June 19, 2014

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

JamieA
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.
June 19, 2014

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)

JamieA
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.
June 19, 2014

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!

Vijay Khacharia
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.
June 19, 2014

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.

Frank Stillone November 17, 2014

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

Kyle Harrison January 21, 2015

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

ChrisR November 10, 2015

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'

JamieA
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.
November 11, 2015

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

ChrisR November 13, 2015

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

JamieA
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.
November 13, 2015

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

0 votes
Nina Zolotova October 11, 2018

@JamieA, thank you, your code helped me a lot!

0 votes
Udo Brand
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.
June 22, 2014

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

0 votes
JamieA
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.
June 22, 2014

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

0 votes
Udo Brand
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.
June 21, 2014

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

0 votes
Sorin Sbarnea (Citrix)
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.
June 21, 2014

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.

0 votes
Udo Brand
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.
June 19, 2014

Why not using simply a filter to identify those reopened issue

status changed from xxx to open

Suggest an answer

Log in or Sign up to answer