Automatically adding a worklog

This script which I got from:, is supposed to automatically add to a worklog when an issue is transitioned to out of some state, but I'm getting a [Static Type Checking] error with the tempoWorklogManager.create method and I believe it is because tempoWorklogManager is now deprecated. So what do I have to do so that the script will run 


Screen Shot 2016-07-29 at 10.27.27 AM.png

1 answer

Is the static type checking error showing up in the input field in JIRA? That may not actually be an issue. The static type checker will err conservatively, meaning that sometimes a script that would work will be listed as having static type checking errors. More advanced scripts like this one are better analyzed using an IDE.

Also, depending on the version of Tempo Timesheets you're using, those examples may not work perfectly. The currently published docs (as of ScriptRunner 4.3.5) were written for Tempo 7. We have updated versions for Tempo 8 forthcoming, and expect them to be published with the next release.

I can get the script to run but it doesn't log work here:
Screen Shot 2016-08-09 at 12.44.48 PM.png

-Any idea why this is happening or what parameter this involves. Thanks!

Did you see my note about Tempo 7 and 8? What version are you using? That may be the source of your issue.

If you're not sure why the script is failing to log time, but running. I'd recommend adding a few log.debug statements. You should be able to see the output of the runs of your post function in the Workflow configuration.

Yeah we are using version 8. Tempo updated the create method - here it is:

public ServiceOutcome<Long> create(String issueKey,
                                       TempoDateTime date,
                                       String comment,
                                       Collection<WorkAttributeValue> worklogAttributes,
                                       long seconds,
                                       long billedSeconds,
                                       long remainingEstimate,
                                       ApplicationUser author,
                                       Map<String, String> analyticsOrigin)

 I got the script to run by passing in null values for Collection<WorkAttributeValue> and Map<String, String> analyticsOrigin parameters because I'm not sure what they are. Work gets logged in the timesheets, but the Time Tracking section doesn't update(the picture I showed above). Did the script update this section in Tempo 7? Is there an estimate on when the next release will be published? Thanks a bunch


So, here's the script as it will appear in the next published set of docs:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.core.workattribute.api.WorkAttributeService
import is.origo.jira.plugin.common.TempoWorklogManager
import com.tempoplugin.core.datetime.api.TempoDateTime


TempoWorklogManager tempoWorklogManager
WorkAttributeService workAttributeService

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

// calculate the time we entered this state
def changeHistoryItems = changeHistoryManager.getAllChangeItems(issue).reverse()
def timeLastStartProgress = changeHistoryItems.find {
    it.field == "status" &amp;&amp; it.toValues.values().contains("In Progress")

def triageType = workAttributeService.getWorkAttributeTypes().returnedValue.find{ == "_WorkType_"}
def attributes =  workAttributeService.getWorkAttributesByType(triageType).returnedValue // set the Tempo Worktype attribute

def timeInProgress = (new Date()).time - timeLastStartProgress.time // this is in millis
def timeToLog = Math.round(timeInProgress.longValue() / 1000) // so round to seconds
def remaining = issue.estimate ? (issue.estimate - timeToLog) : 0 // calc remaining estimate

tempoWorklogManager.create(issue.key,, "Auto-created worklog for triage",
        timeToLog, 0, remaining,
        currentUser, [:])

I don't have a hard date on 4.3.6, but we typically don't have more than a couple of months between releases. 

Okay, thanks a lot Jonny! 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 09, 2018 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

247 views 6 0
Join discussion

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