Tempo

This page gives guidance on using ScriptRunner with Tempo Timesheets for Jira to fulfil basic scripting needs, 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 core of this approach lies in the two annotations discussed in Scripting Other Plugins, namely @WithPlugin and @PluginModule.

These examples use Tempo Timesheets for Jira version 10. For information that works in previous versions, see previous versions of this page.

Examples

Summing worklogs with an attribute

Tempo allows you to categorize worklogs with additional attributes. For example, we have a checkbox attribute called Overtime, and we’d like to display the total overtime on each issue.

  1. We configure the Overtime attribute as follows:
  2. Set up a custom scripted field. In this example, we call it Total Overtime. For this example we use the following script:

    Make sure to use the Duration (time-tracking) template

    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

    If you need to get the ID of your tempo attribute you can use the following script:

    groovy
    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.WorkAttribute @WithPlugin("is.origo.jira.tempo-plugin") @PluginModule WorkAttributeService workAttributeService def attributes = workAttributeService.workAttributes.returnedValue as Collection<WorkAttribute> def overtimeAttribute = attributes.find { it.getName() == "Overtime" } overtimeAttribute.key


Once configured, 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.

On this page