Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,369,457
Community Members
 
Community Events
168
Community Groups

How to get application user instead of delegating app user Groovy

Hello, 

I am trying to create a script that copies the value from a select list field, adds a suffix to it, and then creates a label with that string, upon issue creation. The post function is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.security.JiraAuthenticationContext;

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()


def ScrumTeamObject = customFieldManager.getCustomFieldObject(12205)
def ScrumTeamValue = issue.getCustomFieldValue(ScrumTeamObject).toString()
ScrumTeamValue.replaceAll(" ","_")
def suffix = "_Team"
def labelToAdd = ScrumTeamValue + suffix

JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext()
ApplicationUser user = authContext.getLoggedInUser()

LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
labelManager.setLabels(user,issue.id,labelToAdd,false,false)

The error is :

 

2021-06-04 11:19:09,668 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'abc'. View here: https://jira-abc/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=abc&descriptorTab=postfunctions&workflowTransition=1&highlight=1
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.label.DefaultLabelManager.setLabels() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, null, String...) values: [MARAMA(JIRAUSER83105), null, Engineering_Team, 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 Script154.run(Script154.groovy:22)

 

We are using crowd, Jira 8.5.3 . How do I get an application user so that I can set the labels?

 

Thank you!

1 answer

1 accepted

1 vote
Answer accepted

Labels needs to be a set, not a string

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events