Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,520
Community Members
 
Community Events
184
Community Groups

Get Count of users whose last login time of last Calendar month

Edited
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 18, 2023

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

2 answers

1 accepted

0 votes
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 18, 2023

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
0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 18, 2023

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.

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 18, 2023

@Aron Gombas _Midori_  Can you please help me with the correct script ? 

Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 18, 2023

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:

excel-user-export.png

Then filter the "Last Login" column and count the matching rows.

See: https://www.midori-global.com/products/better-excel-exporter-for-jira/data-center/documentation/user-export

Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 18, 2023

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. 

Suggest an answer

Log in or Sign up to answer