Forums

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

Correct way to get an ApplicationUser

Tyler Brown-Jones June 7, 2018

Hi

Just wondering the correct way to get an ApplicationUser to be used within a service e.g 

UserManager.getUserByName("User")

Hope someone can help

Thanks 

Tyler

2 answers

1 accepted

5 votes
Answer accepted
Alexey Matveev
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.
June 7, 2018

If you want to get a user by name then you can use:

def user = ComponentAccessor.getUserManager().getUserByName("user name")

Tyler Brown-Jones June 7, 2018
import com.atlassian.jira.user.util.UserManager 

Is this the correct import for this?

 

Thanks Alexey, i will also respond to the other request i made explaining my reworked service code and what was wrong with it for future reference.

 

Appreciate the support you have provided me the past couple of days!

Alexey Matveev
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.
June 7, 2018

You should add 

import com.atlassian.jira.component.ComponentAccessor
1 vote
Mark Markov
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.
June 7, 2018

Hello @Tyler Brown-Jones

Depends on your case.

To get current user you can use 

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

 

Tyler Brown-Jones June 7, 2018

I'm trying to get a user within the Jira user manager as it is running as a service within Jira, Not running as a LoggedInUser. 

 

I previously used this way within my Script Listener and understand how it works. I also tried using it within my service and it didn't like it.

 

Many thanks for the response though!

Suggest an answer

Log in or Sign up to answer