Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to get users from a list in Scriptrunner


I probably have a very simple problem but I can't seem to solve it.  I've been given a pretty long list of current users that no longer need access to Jira and I need to deactivate them.  This is a one off problem, so I don't really need a repeatable solution.

What I'm trying to do is to just run a script that will deactivate all the users in the list by their Jira ID.  I have the code written to successfully do this for just one user and which should iterate through a list, but I can't get a predefined list to work as the input.

Here's my current code:

import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.util.UserUtil

UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService userService = ComponentAccessor.getComponent(UserService)
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
UserSearchParams userSearchParams = new UserSearchParams(false,true,false);
List<ApplicationUser> userList = userSearchService.findUsers("a451131", userSearchParams);
ApplicationUser updateUser
UserService.UpdateUserValidationResult updateUserValidationResult

GroupManager groupManager = ComponentAccessor.getGroupManager();

userList.findAll{it.isActive()}.each {
    UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
            updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser())
            updateUserValidationResult = userService.validateUpdateUser(updateUser)
            if (updateUserValidationResult.isValid()) {
       "Deactivated ${}"
            } else {
                log.error "Update of ${} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"


I obviously need to do something with the line: 

List<ApplicationUser> userList = userSearchService.findUsers("a451131", userSearchParams);

But I don't know what to replace this with to use a defined list.

This defined list will be something like:

def DeactivateUsers = [



1 answer

0 votes
Tom Lister Community Leader Dec 02, 2022

Hi @Jeremy Jedlicka 

I have some user manipulation scripts in my GitHub e.g.

If you have a fixed list of usernames, you can still loop through them with DeactivatedUsers.foreach() . You will need to get hold of the UserManager and use one of the getUser methods e.g. getUserByName to get the ApplicationUser object

also check out 

def userUtil = ComponentAccessor.getUserUtil()
For some useful helper methods. Some my usages may be deprecated by now.

Suggest an answer

Log in or Sign up to answer