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

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

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<Label> labels = new HashSet<Label>();
labels.addAll(mutIssue.getLabels());
labels.addAll(LabelParser.buildFromString("New Label"));
mutIssue.setLabels(labels);

0 votes
Henning Tietgens Community Champion Dec 01, 2016

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)

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,864 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot