I have a groovy script that I use to query for a list of users that have not logged into JIRA for 180 days. I need to modify the script to create a list of users that have never logged in and whose account was created over 180 days ago. Is there a way to do that?
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
import org.apache.log4j.Level
import org.apache.log4j.Logger
def log = Logger.getLogger("Debug.Test")
log.setLevel(Level.DEBUG)
int numOfDays = 180 // 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 oldUserCount = 0
long totalUserCount = 0
userUtil.getUsers().findAll{it.isActive()}.each {
totalUserCount++
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)) {
oldUserCount++
}
}
else {
// Need code here to identify users whose accounts were created over 180 days ago.
}
}
log.debug "${totalUserCount} active users\n"
log.debug "${oldUserCount} old users\n"
Hello O.,
it looks like this information is not available through JIRA Java API and you would need executing custom SQL script:
Regards,
Martin
Thank you! I was able to build on top of the following Groovy script that connects to the database and got it working.
https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/connecting-to-databases.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.