I'm trying to get the number of users who became Inactive within the past year.
I followed this script https://library.adaptavist.com/entity/retrieve-list-of-inactive-users and added a table to print the list for me, but the problem is the script still pulls up all Inactive users. Meaning I'm seeing users last login since 2015 when I just want to see inactive users whose last login was within 2022.
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.CrowdService
import groovy.xml.MarkupBuilder
import java.time.LocalDateTime
import java.time.Instant
import java.time.ZoneId
def crowdService = ComponentAccessor.getComponent(CrowdService)
def result ="<table class='aui'"
// review in the last year
def numOfDays = 365
def dateLimit = LocalDateTime.now().minusDays(numOfDays)
// Search all inactive users
UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.allowEmptyQuery(true)
.includeActive(false)
.includeInactive(true)
def jiraServiceContext = new JiraServiceContextImpl(ComponentAccessor.jiraAuthenticationContext.loggedInUser)
def allInactiveUsers = ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, '', paramBuilder.build())
// Users which last activity is after limit date
def inactivePastYear = allInactiveUsers.findAll { user ->
def userWithAtributes = crowdService.getUserWithAttributes(user.username)
def lastLoginMillis = userWithAtributes.getValue('login.lastLoginMillis')
if (lastLoginMillis?.number) {
def lastLogin = Instant.ofEpochMilli(Long.parseLong(lastLoginMillis)).atZone(ZoneId.systemDefault()).toLocalDateTime()
if (lastLogin.isAfter(dateLimit)) {
def sb = new StringBuffer()
result+="<tr><td>${user.displayName}</td><td>${lastLogin.toString()</tr><td>"}
}
}
result +="</table>"
return result
Is there a way, maybe, I can have the script check between 2 dates? Between start of Year to end of Year?