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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to bulk disable/inactive users in jira on csv file using scriptrunner

 Hi Community,

Good day! Just want to ask if how can I bulk disable/inactive users in JIRA  on csv file using scriptrunner? Currently I'm using this code to disable single user but I do want to do this on bulk and get users from csv file instead of hardcode.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.user.DelegatingApplicationUser
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.UserService
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def jiraServiceContext = new JiraServiceContextImpl(currentUser)
def userSearchService = ComponentAccessor.getComponent(UserSearchService.class)
def userService = ComponentAccessor.getComponent(UserService.class)
def userlist = ['alvin_sample', 'alvin_cust']
for (item in userlist) {
def appUser = userSearchService.getUserByName(jiraServiceContext, 'test')
def errors = ''
if (appUser != null) {

ImmutableUser.Builder builder = ImmutableUser.newUser(appUser.getDirectoryUser());
builder.active(false)
//builder.displayName('New display name')
//builder.emailAddress('newemail@somewhere.com')
def updateUser = new DelegatingApplicationUser(appUser.getId(), appUser.getKey(), builder.toUser());

def updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
} else {
errors += "Update of ${appUser.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\n"
}
}

 

Any help is appreciated. thank you!

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,894 views 11 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you