Hi Guys,
Need your help in fixing my script. I am trying to get a Count of the JIRA users last login time of last calendar month. Like User whose last login time between 1st March to 31st March.
Getting this error message :-
groovy.lang.MissingMethodException: No signature of method: java.lang.Long.between() is applicable for argument types: (Date, Date) values: [Wed Mar 01 23:49:00 PST 2023, Fri Mar 31 23:49:00 PDT 2023]
at Script3103$_run_closure1.doCall(Script3103.groovy:27)
at Script3103.run(Script3103.groovy:26)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import java.util.Date;
import com.atlassian.jira.user.util.UserUtil
UserUtil userUtil = ComponentAccessor.getUserUtil()
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
def groupManager = ComponentAccessor.getGroupManager()
def adminGroup = groupManager.getUsersInGroup('jira-administrators')
def softwareGroup = groupManager.getUsersInGroup('jira-users')
def users = adminGroup + softwareGroup
users.unique()
// Get the start and end dates of the last calendar month
Calendar cal = Calendar.getInstance()
cal.add(Calendar.MONTH, -1)
cal.set(Calendar.DAY_OF_MONTH, 1)
Date startDate = cal.time
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH))
Date endDate = cal.time
def activeUsersWithLoginLastMonth = users.findAll { user ->
user.isActive() && loginManager.getLoginInfo(user.username)?.getLastLoginTime()?.between(startDate, endDate)
}
def countActiveUsersWithLoginLastMonth = activeUsersWithLoginLastMonth.size()
return countActiveUsersWithLoginLastMonth
Correct Script to get count of User Last login Date is Previous Calendar Month:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.atlassian.jira.user.util.UserUtil
UserUtil userUtil = ComponentAccessor.getUserUtil()
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
def groupManager = ComponentAccessor.getGroupManager()
def adminGroup = groupManager.getUsersInGroup('jira-administrators')
def softwareGroup = groupManager.getUsersInGroup('jira-users')
def users = adminGroup + softwareGroup
users.unique()
def activeUsers = users.findAll { user ->
user.isActive()
}
def calendar = Calendar.getInstance()
calendar.set(Calendar.DAY_OF_MONTH, 1)
calendar.add(Calendar.MONTH, -1)
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
def startDate = calendar.time
log.warn startDate
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH))
calendar.set(Calendar.HOUR_OF_DAY, 23)
calendar.set(Calendar.MINUTE, 59)
calendar.set(Calendar.SECOND, 59)
def endDate = calendar.time
log.warn endDate
def sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
def count = activeUsers.count { user ->
Long lastLoginTime = loginManager.getLoginInfo(user.username)?.getLastLoginTime()
if (lastLoginTime != null && lastLoginTime >= startDate.getTime() && lastLoginTime <= endDate.getTime() ) {
true
} else {
false
}
}
return count
The problem is that in this line:
loginManager.getLoginInfo(user.username)?.getLastLoginTime()?.between(startDate, endDate)
getLastLoginTime() returns a Long. And Long doesn't have a between() method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aron Gombas _Midori_ Can you please help me with the correct script ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, I don't have the time for the bugfix, sorry.
If that's an option for you, you could use our app to export the users to an Excel spreadhsheet like this:
Then filter the "Last Login" column and count the matching rows.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Aron Gombas _Midori_ I already have script for exporting JIRA Users Data in csv. No need of new plugin. :)
Anyway, thanks for your help. I have fixed my script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @vasanth
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.atlassian.jira.user.util.UserUtil
UserUtil userUtil = ComponentAccessor.getUserUtil()
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
def groupManager = ComponentAccessor.getGroupManager()
def adminGroup = groupManager.getUsersInGroup('jira-administrators')
def softwareGroup = groupManager.getUsersInGroup('jira-software-users')
def users = adminGroup + softwareGroup
users.unique()
def activeUsers = users.findAll { user ->
user.isActive()
}
def calendar = Calendar.getInstance()
calendar.set(Calendar.DAY_OF_MONTH, 1)
calendar.add(Calendar.MONTH, -1)
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
def startDate = calendar.time
log.warn startDate
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH))
calendar.set(Calendar.HOUR_OF_DAY, 23)
calendar.set(Calendar.MINUTE, 59)
calendar.set(Calendar.SECOND, 59)
def endDate = calendar.time
log.warn endDate
def sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
def count = activeUsers.count { user ->
Long lastLoginTime = loginManager.getLoginInfo(user.username)?.getLastLoginTime()
if (lastLoginTime != null && lastLoginTime >= startDate.getTime() && lastLoginTime <= endDate.getTime() ) {
true
} else {
false
}
}
return count
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Vikrant Yadav
my request is to remove inactive and no longer active users in jira
I couldn't get a solution for this.
we have the user's login with the Active directory
can you help me on this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@vasanth You can check this script : https://library.adaptavist.com/entity/deactivate-inactive-users-after-custom-period
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.