Any way to remove a Label on Resolution?

I'm very familiar with adding Post Functions to alter an issue during a transition. The problem is that I can't seem to find a way to remove one particular label during transition to Resolution. I can clear the entire field, but that is not desirable.

I have also tried to create a Condition to prevent Resolution of an issue if the label is present, but this didn't appear to work either. A few comments by Atlassian employees imply that Conditions can't work with the system Labels field.

4 answers

1 accepted

Accepted Answer
10 votes
Henning Tietgens Community Champion May 22, 2013

You could use the Script Runner plugin and the following script for a start.

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)

The script is not tested by me, so be careful :-)

Henning

Is there any way to do this with the hosted version of Jira these days? We use a label of "merged" when branch code is merged into master and handed over to QA. but when QA re-opens the ticket, we wish to have that transition automatically remove said label if it exists (and of course, leave all the other labels !!!)

script is also helpful after 3 years wink worked perfectly after changing line 4 to:
 
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
 

For JIRA v7.x you need to change line 4 to:

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

Henning Tietgens Community Champion Jan 19, 2017

Hi Ville-Pekka, 

that's exactly what's written in line 4. It's only another notation. In Groovy you could replace abc.getXyz() method calls with property access abc.xyz (remove get from the name, remove () and write the first letter in lower case). See http://groovy-lang.org/style-guide.html#_getters_and_setters

It could be written even shorter with 

ComponentAccessor.jiraAuthenticationContext.loggedInUser


Henning

Oops. Way too long day behind last night smile

I did not even tested original code, but modified it first according to Alexander's comment.

Anyway this code is working and in our production now.

Hi Henning,

how can i do this with a custom-field from type label?

thx

Yes, I meant Labels. I've adjusted the question to indicate this. Thanks!

0 votes
Timothy Chin Community Champion May 22, 2013

Tags is Labels right?

0 votes
Timothy Chin Community Champion May 22, 2013

I think the best way for you is to use Script Runner's post function

https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 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...

25,019 views 2 7
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