SriptRunner custom listener that clears label field on cloned bug does not work in version 5

helen levich
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.
April 23, 2019

We have SriptRunner custom listener that clears label field on cloned bug. It stopped working with upgrade to Jira 7/ScriptRunner 5.

Please advice. Thank you

Script:

import org.apache.log4j.Logger;
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import com.atlassian.jira.issue.label.LabelManager

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink;

//Issue Service
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters

import webwork.action.ActionContext


// Logger
Logger log = Logger.getLogger("LABEL::");
// Set the logging level to INFO/DEBUG as needed
log.setLevel(org.apache.log4j.Level.DEBUG);
def logPrefix = "LABEL:: ";
logPrefix = logPrefix + event.issue.getKey() + ":: ";

log.debug(logPrefix)

try
{
log.debug(logPrefix + "TRY Block... START")
if(event.issue.getIssueType().name == "Bug")
{

def linkedissueId = event.issue.getId()
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def loggeduser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(linkedissueId).collect{it.getLabel()}
labels = []
labelManager.setLabels(loggeduser.getDirectoryUser(),linkedissueId,labels.toSet(),false,false)

}


log.debug(logPrefix + "TRY Block... END")
}
catch(Exception e)
{
log.error(e.getMessage())
}

 

ClearLabelinClonedBug1.png

Line 41 labelManager.setLabels(loggeduser.getDirectoryUser(),linkedissueId,labels.toSet(),false,false)

shows

[Static type checking] - Cannot find matching method com.atlassian.jira.issue.label.Labelmanager#setlabels(com.atlassian.crowd.embedd java.lag.Long, java.util.Set<java.lang.String>, boolen, boolen) Please check if the declared type is right and if the method exits. @Line 41, column 5

 

And script does not work. :(

 

 

 

 

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2019

I think you just need to replace

labelManager.setLabels(loggeduser.getDirectoryUser(),linkedissueId,labels.toSet(),false,false)

with

labelManager.setLabels(loggeduser,linkedissueId,labels.toSet(),false,false)
helen levich
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.
April 23, 2019

Thank you  very much, that fixed the problem. 

Suggest an answer

Log in or Sign up to answer