Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Retrieve List of Inactive Users

Created 1 year ago, Updated 0 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.5 - 8.22)
compatibility bullet
ScriptRunner For Jira (6.45.0)
Language |
groovy
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor

def userSearchService = ComponentAccessor.getComponent(UserSearchService)

final def limitValue = '<SPECIFY_VALUE>'
//Build a search with 100,000 results where users are inactive
def userSearchBuilder = new UserSearchParams.Builder(limitValue)
def userSearchParams = userSearchBuilder.allowEmptyQuery(true)
        .includeActive(false)
        .includeInactive(true)
        .limitResults(limitValue)
        .build()

//Retrieve immutableList of Inactive Users
def inactiveUsers = userSearchService.findUsers('', userSearchParams)

//You can convert immutableList inactiveUsers, to a List<String> with below
//which is useful for method like ProjectRoleService.removeActorsFromProjectRole()
def usersToRemove = [] as List<String>
inactiveUsers.each {
    usersToRemove.add(it.key.toString())
}
Having an issue with this script?
Report it here