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!
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)
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oh okay anyways if this thing resolves just give out the solution if this is new then it might help others
thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.