Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Published in Apps & Integrations

Partner Webinar Opportunities: January 2022

Hi everyone 👋, I really like the format of the webinar opportunities summary that @Jimmy Seddon posts monthly on the Welcome Centre group. It's a great place to go to check that you didn...

91 views 1 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you