Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot copy labels from issue to linked issues through script

Mihai Mihai
Contributor
October 16, 2019

Hello,

 

I am trying to copy the labels on an existing issue to its linked issues (through a certain link).

I am pretty close, but I get an error I'm not sure how to overcome:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.label.LabelManager
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issue = event.issue
def labelManager = ComponentAccessor.getComponent(LabelManager)
def existingLabels = labelManager.getLabels(issue.id).collect{it.getLabel()}
def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def subElements = links.findAll { it.issueLinkType.name.contains('Parent/Child') && it.destinationObject.getProjectObject().getKey() == 'TEST'}


subElements.each { it ->

def sublabelManager = ComponentAccessor.getComponent(LabelManager)
def subexistingLabels = sublabelManager.getLabels(it.getDestinationObject().id)*.label
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

for (eachlabel in existingLabels) {

if (eachlabel && !subexistingLabels*.contains(eachlabel)) {

labelManager.setLabels(loggedInUser, it.getDestinationObject().key, eachlabel, false, false)
}
}
}

 

The error is:

 

2019-10-17 07:15:24,744 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-10-17 07:15:24,744 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.label.DefaultLabelManager.setLabels() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, java.lang.String, java.lang.String, java.lang.Boolean, java.lang.Boolean) values: [uidq5816(uidq5816), TEST-1001, a2b, false, false]
Possible solutions: setLabels(com.atlassian.jira.user.ApplicationUser, java.lang.Long, java.util.Set, boolean, boolean), setLabels(com.atlassian.jira.user.ApplicationUser, java.lang.Long, java.lang.Long, java.util.Set, boolean, boolean)
	at Script686$_run_closure3.doCall(Script686.groovy:24)
	at Script686.run(Script686.groovy:14)


Any help is appreciated.

Thank you!

 

2 answers

1 accepted

1 vote
Answer accepted
Mihai Mihai
Contributor
October 18, 2019

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.label.LabelManager
import org.springframework.util.StringUtils
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.listener")
log.setLevel(Level.DEBUG)

def issue = event.issue
def labelManager = ComponentAccessor.getComponent(LabelManager)
def existingLabels = labelManager.getLabels(issue.id).collect{it.getLabel()} as Set
def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def subElements = links.findAll { it.issueLinkType.name.contains('Parent/Child') && it.destinationObject.getProjectObject().getKey() == 'TEST'}


subElements.each { it ->

def sublabelManager = ComponentAccessor.getComponent(LabelManager)
def subexistingLabels = sublabelManager.getLabels(it.getDestinationObject().id).collect{it.getLabel()} as Set
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

log.debug("labels on current issue: " + existingLabels)
log.debug("subexistingLabels: " + subexistingLabels)

for (eachlabel in existingLabels) {
if (!subexistingLabels.contains(eachlabel)) {
subexistingLabels.add(eachlabel)

labelManager.setLabels(loggedInUser, it.getDestinationObject().id as Long, subexistingLabels, false, false)
}
}

}

Mihai Mihai
Contributor
October 16, 2019

Hi,

Not sure how that can help, it seems I'm just having issues with my last line:

 

labelManager.setLabels(loggedInUser, it.getDestinationObject().key, eachlabel, false, false)

 

while in there there is a totally different approach.

 

Thank you.

Kevin Johnson
Community Champion
October 16, 2019

oh okay anyways if this thing resolves just give out the solution if this is new then it might help others 

thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events