Scriptrunner - get active users who's not logged in for the past 90 days

Jakob KN
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2025

Hi! 

I'm trying to retrieve users who's account is active, but who either haven't logged in for 90 days, or who's never logged in. 

With the script below i get users as expected based on login times/no login, but it also returns users who's been deactivated.

I think I can use the com.atlassian.jira.user.ApplicationUser property called "isActive", but I'm not sure how to correctly add it in the script. 

Any help is much appreciated!

 

 

import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager


def userManager = ComponentAccessor.getUserManager()
def loginManager = ComponentAccessor.getComponent(LoginManager)

ArrayList oldUsers = new ArrayList()
Date today = new Date()
//CHANGE TO DESIRED AMOUNT
int threshold = 90

userManager.allApplicationUsers.toList().each { user ->
def loginfo = loginManager.getLoginInfo(user.username)

if (loginfo.getLastLoginTime() == null) {
oldUsers.add(user.displayName)
}
else {
def lastLogOn = new Date(loginfo.getLastLoginTime())
def difference = today.minus(lastLogOn)
if (difference >= threshold) {
oldUsers.add(user.displayName)
oldUsers.add(lastLogOn)
}
}
}

return oldUsers

1 answer

0 votes
Jakob KN
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2025

In addition, but similar, to the above. 
I'd also like to extract all users with their usernames, emails and last login date. 
I'm assuming it'll be a script similar to the above.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.18
TAGS
AUG Leaders

Atlassian Community Events