Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I set labels using the clone issue post-function from Script Runner?

B. Nana September 26, 2013

This may be an extremely noob question but how do I set a label in the Additional issue actions? I can see how to set specific fields, but I can't see the method for labels (I tried the custom field script, but that didn't work either).

2 answers

2 votes
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.
December 1, 2016 edited

A small problem with Rambanams code is, that the issue doesn't exist at the time the additional issue actions are executed. The following slightly modified code works:

import com.atlassian.jira.issue.label.Label
import com.atlassian.jira.issue.label.LabelParser


def labels = new HashSet<Label>()
labels.addAll(issue.labels)
labels.addAll(LabelParser.buildFromString("NewLabel"))
issue.setLabels(labels)
SS
Contributor
May 4, 2022

I have been bashing my head against the wall for days with this exact problem.

Big Thanks.

2 votes
RambanamP
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.
September 26, 2013

the following code we use in java, so you can convert to groovy

import com.atlassian.jira.issue.label.Label;
import com.atlassian.jira.issue.label.LabelParser;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;


MutableIssue mutIssue =ComponentAccessor.getIssueManager().getIssueObject(issue.getKey());
Set&lt;Label&gt; labels = new HashSet&lt;Label&gt;();
labels.addAll(mutIssue.getLabels());
labels.addAll(LabelParser.buildFromString("New Label"));
mutIssue.setLabels(labels);

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events