Any way to remove a Label on Resolution?

Jo Rhett May 21, 2013

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

10 votes
Answer accepted
Henning Tietgens
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.
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

David Elman March 18, 2015

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 !!!)

Alexander Richter
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.
July 24, 2016

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

vahtis January 19, 2017

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

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

Henning Tietgens
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.
January 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

vahtis January 19, 2017

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.

Martin Schmalz March 1, 2018

Hi Henning,

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

thx

Henning Tietgens
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.
March 4, 2018
Randy_Elias June 16, 2020

Hi,

 

    I'm using JIRA v8.3.1 using the scriptrunner code above to clear the Label field. It's not clearing the field and I get no errors when it's run. Is there anything I need to do in my version of JIRA to get the Labels field to clear in Scriptrunner?

 

Thanks,

   Randy

Randy_Elias June 16, 2020

Please disregard. Found a solution to my issue. I wanted to clear ALL labels so I used this code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

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

LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(issue.id).collect{it.getLabel()}
labels = ''
labelManager.setLabels(user,issue.id,labels.toSet(),false,false)
0 votes
Timothy
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.
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

0 votes
Timothy
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.
May 22, 2013

Tags is Labels right?

0 votes
Jo Rhett May 22, 2013

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

Suggest an answer

Log in or Sign up to answer