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?
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.