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

sort worklogs base on start date in script runner

Edited

hi

I want show first worklog date (base on start date, not create date) in a date field.

this is my code that use worklog list and get first element of list. but this is base on work log created date, not base on worklog start date.

WorklogManager worklogManager = ComponentAccessor.getWorklogManager()
List<Worklog> worklogList = worklogManager.getByIssue(issue)
Worklog firstWorklog = worklogList[0]
return firstWorklog.getStartDate()

 this code return start date of first created worklog but I want to show start date of first worklog base on start date. in other words I need a worklog list that sort base on worklog start date but worklogManager.getByIssue(issue) return a worklog list that sort base on worklog create date.

any help for this ?!

thanks

2 comments

Alexey Matveev
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.
Nov 08, 2017

Hello,

The code would be like this

List<Worklog> worklogList = worklogManager.getByIssue(issue)
List<Worklog> resultList = worklogList.stream().sorted(new Comparator<Worklog>() {
@Override
public int compare(Worklog o1, Worklog o2) {
if (o1.getStartDate().compareTo(o2.getStartDate()) == 0) {
return 0;
} else if (o1.getStartDate().compareTo(o2.getStartDate()) > 0) {
return 1;
} else if (o1.getStartDate().compareTo(o2.getStartDate()) < 0) {
return -1;
}
return 0;
}
}).collect(Collectors.toList());
Worklog firstWorklog = resultList[0]
return firstWorklog.getStartDate()

  

thank for your help

must I import any thing for these functions ?!

ok, I solved problem with this code :

WorklogManager worklogManager = ComponentAccessor.getWorklogManager()
List<Worklog> worklogsList = worklogManager.getByIssue(issue)
Worklog firstWorklog
for (item in worklogsList){
if (firstWorklog == null){
firstWorklog == item
}
if (item.getStartDate().getTime() < firstWorklog.getStartDate().getTime()){
firstWorklog = item
}
}
return firstWorklog.getStartDate()
Juan José Marchal Gómez
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.
Feb 24, 2020

The code has an error with == instead of =.

 

Here you are the correct code:

 

WorklogManager worklogManager = ComponentAccessor.getWorklogManager()
List<Worklog> worklogsList = worklogManager.getByIssue(issue)
Worklog firstWorklog
for (item in worklogsList){
if (firstWorklog == null){
firstWorklog = item
}
if (item.getStartDate().getTime() < firstWorklog.getStartDate().getTime()){
firstWorklog = item
}
}
return firstWorklog.getStartDate()

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events