Forums

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

Scriptrunner HAPI Way to get all Users?

Alexander Mateasik April 2, 2025

Hi, i get all Users with the following code:


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams

def userManager = ComponentAccessor.getUserManager()
def userSearchService = ComponentAccessor.getUserSearchService()
def userSearchParams = new UserSearchParams.Builder()
.allowEmptyQuery(true)
.canMatchEmail(true)
.includeActive(true)
.includeInactive(true)
.sorted(true)
.maxResults(userManager.getTotalUserCount())
.build()

def AllUserList = userSearchService.findUsers('', userSearchParams)

AllUserList.each {
log.warn(it)
}


Is there a more Scriptrunner HAPI Way to get all Users? 


3 answers

1 vote
Fabio Racobaldo _Herzum_
Community Champion
April 2, 2025

Hi @Alexander Mateasik and welcome,

you can use UserManager api class and getAllApplicationUsers() method (https://docs.atlassian.com/software/jira/docs/api/10.5.0/com/atlassian/jira/user/util/UserManager.html#getAllApplicationUsers())

Hope this helps,

Fabio

0 votes
Alexander Mateasik April 2, 2025

Hey, I used to solve this with getAllApplicationUsers (). At some point, I saw that it was set to Deprecated and modified it to the UserSearchService.

Deprecated.
Since v7.0. Only retrieve the users you really need. See UserSearchService

But I am currently switching all scripts to HAPI due to better readability -> https://docs.adaptavist.com/sr4js/8.5.0/hapi and i want to ask if anyone has solved this with the HAPI Way.

0 votes
Tuncay Senturk
Community Champion
April 2, 2025

Hi @Alexander Mateasik 

I would also recommend using the getAllApplicationUsers method from the UserManager service class, as @Fabio Racobaldo _Herzum_ mentioned. The UserSearchService is primarily used to filter users based on specific search criteria.

Tuncay Senturk
Community Champion
April 2, 2025
You're absolutely right @Alexander Mateasik. That's deprecated already, sorry for not taking that into account. 
Could you try this?
import static com.adaptavist.hapi.jira.users.Users.*

def allUsers = getUsers().toList()

allUsers.each {
log.warn(it)
}

It returns all active users. If you need to filter the users, you can do it Groovy style with the returned list.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events