Retrieve an issue's worklogs by date using groovy

Alex Christensen Community Champion Nov 11, 2015

I am trying to pull only certain worklogs for a certain issue based on the date the worklog was created. I am using the PDF View Plugin to create a report and I need to get an issue's worklogs.

Below is a snippet of code I'm using to create a series of plot points to be used in a line graph.

actualSeries = new TimeSeries("actual")
def totalRemainingEstimate = totalOriginalEstimate
actualSeries.add(preDate, totalRemainingEstimate)
def worklogManager = ComponentAccessor.getWorklogManager()
for (date in startDate..now) {
	def timeSpent = 0
	def currDate = new Day(date)
	issues.each {
		List worklogs = worklogManager.getByIssue(it)
		for (def worklog : worklogs) {
			def created = new Day(worklog.getCreated())
				if (created == currDate) {
					timeSpent += (worklog.getTimeSpent()/3600)
				}
		}
}
totalRemainingEstimate -= timeSpent
actualSeries.add(currDate, totalRemainingEstimate)

This code works correctly and it does what I need it to, but is there a way to only pull the worklogs for an issue based on a particular date instead of pull ALL worklogs? It's unnecessary to pull all of the worklogs and I think it's extra work for the system to pull all worklogs instead of just the ones that I need.

1 answer

1 accepted

0 vote

There is nothing in the API to support that AFAIK. You could do a lucene query on the worklog index (6.4+) but I don't think it's worth the trouble, and may not use any less resources.

You could use com.atlassian.jira.issue.worklog.WorklogManager#getByIssue(com.atlassian.jira.issue.Issue, int), so get a paged list. If you use a page size of say 2 or 3, you're unlikely to ever need the second page if just looking for the current day.

Again, I'm not sure that's worth the trouble either.

Alex Christensen Community Champion Nov 11, 2015

Thanks, Jamie! I'll take your word for it here - if I find anything that might help, I'll let you know here.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published yesterday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

428 views 5 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you