Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

List of all users (only active ) Scriptrunner

Edgar Pusklevic June 28, 2024

Hi , 
I want to get all active users who has logged in more than 31 day...

with this script , I have inactive users also.. how to get list of only active users ?

 

 

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 = 31

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)
}
}
}

return oldUsers

 

1 answer

0 votes
Graham Twine
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.
June 28, 2024

Hello @Edgar Pusklevic

 

The com.atlassian.jira.user.ApplicationUser has a property isActive

You can check this flag as well to see if a person is active.

Use the user search service and add a query filter to only return active users.

 

 

Suggest an answer

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

Atlassian Community Events