Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

scriptRunner deactivate all user that never been logged in


I have a script that desactivate all users that are inactive, it works fine, now I need to desactive all users that never been logged in

this is my script 

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

def loginManager = ComponentAccessor.getComponent(LoginService)
int numOfDays = 100 // Number of days the user was not logged in
Date dateLimit = (new Date())- numOfDays

UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUser updateUser
UserService.UpdateUserValidationResult updateUserValidationResult

long count = 0
def list = ['115058']
def userIsInList = false

userUtil.getUsers().findAll{it.isActive() || !loginManager.getLoginInfo(it.username).lastLoginTime}.each {
UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
String lastLoginMillis = user.getValue('login.lastLoginMillis')
if (lastLoginMillis?.isNumber()) {
Date d = new Date(Long.parseLong(lastLoginMillis))
if (d.before(dateLimit) && !( in list) ) {
updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser())
updateUserValidationResult = userService.validateUpdateUser(updateUser)
//if (count < 10) {
if (updateUserValidationResult.isValid()) {

// "Deactivated ${}"

count++ "this one --> ${user.displayName}"
} else { "Update of ${} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"

"${count} users deactivated.\n"


I think !loginManager.getLoginInfo(it.username).lastLoginTime is a wrong condition 

have you any idea please?


Thank you


1 answer

0 votes
Hana Kučerová Community Leader Mar 24, 2021

Hi @Firas hammami ,

according to this script the condition


looks ok.

I think the problem is you are later checking last login, but these users don't have any. 

So these users won't get through the condition:

if (lastLoginMillis?.isNumber()) {


thank you for your respense, I tried to put 


outside the  condition 

if (lastLoginMillis?.isNumber())  

 I dont't have any output 

Hana Kučerová Community Leader Mar 26, 2021

Hi @Firas hammami ,

please, what do you mean by you don't have any output?

What I was trying to say is that you need to deactivate two different groups of users.

How does your code looks like now?

Thank you.

Suggest an answer

Log in or Sign up to answer

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