How to set a custom field of type label during the cloning post function?

Hi, I have a question, that is probably rather simple to solve for you.

On there is described how to set issue attributes. Now I'd like to set a custom field of type label while cloning an issue with the post function "Clones an issue and links".

I tried (the first three lines are working):

issue.summary = "CR: " + sourceIssue.summary
com.atlassian.crowd.embedded.api.User user = sourceIssue.getReporter()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject("customfield_10701")
issue.setCustomFieldValue(cf, "Implementation")


LabelsCFType.createValue(CustomField cf, Issue issue, Set<Label> "Implementation")

which I found somewhere else.

I also tried

def cf = customFieldManager.getCustomFieldObjects(issue).find { == "my_custom_field"}

instead of using the fields' ID, but it didn't work either.

So could you please help me with setting a label in a custom label field during cloning post function?

Thanks in advance, Robert

1 answer

1 accepted

2 votes

You can do it like this, in the additional code area:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.Label
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def labelsCf = customFieldManager.getCustomFieldObjectByName("Some Labels Custom Field")
def fooLlabel = new Label(null,, labelsCf.idAsLong, "foo")
def barLlabel = new Label(null,, labelsCf.idAsLong, "bar")
issue.setCustomFieldValue(labelsCf, [fooLlabel, barLlabel] as Set)

Change custom field name and label names.


Works like a charm! Thank you!

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

181 views 0 4
Read article

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