Tempo
This page gives some guidance on how to use ScriptRunner to work with Tempo Timesheets for Jira, to accomplish some basic scripting requirements, such as:
sum worklogs with a specific attribute, for example to display on the issue the amount of Overtime
aggregate worklogs
auto-create worklogs
The cornerstone of this is the two annotations discussed in Scripting Other Plugins, namely @WithPlugin and @PluginModule .
Let’s dive straight into the examples.
These examples use Tempo Timesheets for Jira version 8. For information that works in version 7, see previous versions of this page.
Examples
Summing worklogs with an attribute
Tempo allows you to categorize worklogs with additional attributes. Let’s say we have a checkbox attribute called Overtime, and we’d like to display the total overtime on each issue.
We configure the Overtime attribute, as in the following example:
Set up a custom scripted field. In this example I’m going to call it Total Overtime. Make sure to use the Duration Searcher as the Search template.
The custom field script is:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.Worklog
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.core.workattribute.api.WorkAttributeService
import com.tempoplugin.core.workattribute.api.WorkAttributeValueService
@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModule
WorkAttributeService workAttributeService
@PluginModule
WorkAttributeValueService workAttributeValueService
def worklogManager = ComponentAccessor.getWorklogManager()
def worklogs = worklogManager.getByIssue(issue)
def overtimeLogs = worklogs.findAll { worklog ->
def attribute = workAttributeService.getWorkAttributeByKey("_Overtime_").returnedValue
workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue
}
overtimeLogs.sum { Worklog worklog ->
worklog.timeSpent
} as Long
// if no overtime worklogs just return null
Use a custom template so that the duration is presented nicely, but note that we return a Long value so the duration searcher can index it properly:
Custom Template
#if ($value)
$jiraDurationUtils.getFormattedDuration($value)
#end
Template | Custom |
Searcher | Duration Searcher |
If configured properly we should be able to search for issues where the overtime has exceeded 4 hours using: "Total Overtime" > 4h
.
Automatically adding a worklog
See an example script for this on the Adaptavist Library.
Population of the dropdown
See an example script for this on the Adaptavist Library.