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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Inactivate jira user automatically via scriptrunner

Need an exact script to inactive the jira users.

we have the users to be inactive in a list and the list of users is to be inactive.

 

1 comment

Adaptavist has a script documented here that will deactivate idle users: https://library.adaptavist.com/entity/deactivate-idle-users

 

Just be sure to test this in a lower environment before deactivating users in production.

Like Suji Shyam likes this

Also a tried a script to inactive the users.

One can run this script in the scriptrunner console and get the users inactivated. Successfully got the result.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.User
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.util.UserManager
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes


UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
UserSearchParams userSearchParams = new UserSearchParams(true, true, false);
//String pattern = "@dummy.com"
List<ApplicationUser> userList = userSearchService.findUsers("","@dummy.com", userSearchParams);
def namePrint = ""
userList.each{
//namePrint += it.displayName
namePrint += it.name + "<br>"
}
// return namePrint.split("<br>") // [appuser242, appuser245, jegi01, sankesw]
String[] nameofactive = namePrint.split("<br>")
int i
for (i=0; i<=nameofactive.size(); i++)
{
CrowdService crowdService = ComponentAccessor.crowdService
UserWithAttributes user = crowdService.getUserWithAttributes(nameofactive[i]);
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUser updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser());
UserService.UpdateUserValidationResult updateUserValidationResult = userService.validateUpdateUser(updateUser)

if (updateUserValidationResult.isValid()) {

userService.updateUser(updateUserValidationResult)

} else {
log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}";

}

}

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

141 views 3 7
Read article

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