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

Deleted user September 24, 2015

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

On https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html 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()
issue.setAssignee(user)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject("customfield_10701")
issue.setCustomFieldValue(cf, "Implementation")

and

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

which I found somewhere else.

I also tried

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "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

5 votes
Answer accepted
JamieA
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 27, 2015

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, issue.id, labelsCf.idAsLong, "foo")
def barLlabel = new Label(null, issue.id, labelsCf.idAsLong, "bar")
 
issue.setCustomFieldValue(labelsCf, [fooLlabel, barLlabel] as Set)

Change custom field name and label names.

 

Deleted user September 28, 2015

Works like a charm! Thank you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events