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 .
Hi, Jagadish
You need to use the addLabel () method from LabelManager:
https://docs.atlassian.com/software/jira/docs/api/8.4.2/index.html?com/atlassian/jira/issue/label/LabelManager.html
An example can be seen here: https://community.atlassian.com/t5/Jira-questions/How-do-I-add-a-label-as-part-of-the-workflow-transition/qaq-p/245365
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.ComponentAccessorimport com.atlassian.jira.issue.label.LabelManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.event.type.EventDispatchOptiondef 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)
If you want to just add label to existing labels on current issue using post function use this.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.label.LabelManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.event.issue.IssueEvent;import com.atlassian.jira.event.issue.IssueEventBundle;import com.atlassian.jira.event.type.EventType;def issueManager = ComponentAccessor.getIssueManager()def issueFactory = ComponentAccessor.getIssueFactory()issueManager = ComponentAccessor.getIssueManager()def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()def labelManager = ComponentAccessor.getComponent(LabelManager.class)labelManager.addLabel(currentUser, issue.getId(), "LABEL_NAME", false)
It need to be in scirpt runner post function then issue object exist and you use issue.getId()
It looks like you're new here. Sign in or register to get started.