It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Appending the update of custom field of type label to already existing value in the field

Whenever i try to update my custom field , the old value gets deleted and the new value takes its place . But here i need the new value to be appended to the old one .

I am using ScriptRunner for jira .

1 answer

Hi @Maksim_Smetannikov

addLabel() doesnt work . Its asking to check if the method exists .

Sorry,  Jagadish

I did not notice that the label field is custom. For a custom field of type label, the answer will look like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption

def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("MYP-1")

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customLabelFieldID = customFieldManager.getCustomFieldObject("customfield_10100").getIdAsLong()
def labelManager = ComponentAccessor.getComponent(LabelManager)

labelManager.addLabel(currentUser, issue.getId(), customLabelFieldID, "123", false)
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you