Automatically adding a worklog

Morgan Stippa July 29, 2016

This script which I got from: https://scriptrunner.adaptavist.com/latest/jira/plugins/working-with-tempo.html, 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

0 votes
Jonny Carter
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.
August 2, 2016

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.

Morgan Stippa August 9, 2016
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!

Jonny Carter
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.
August 9, 2016

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.

Morgan Stippa August 16, 2016

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

 
Jonny Carter
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.
August 17, 2016

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

@WithPlugin("is.origo.jira.tempo-plugin")

@PluginModule
TempoWorklogManager tempoWorklogManager
@PluginModule
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")
}?.created

def triageType = workAttributeService.getWorkAttributeTypes().returnedValue.find{it.name == "_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, TempoDateTime.now(), "Auto-created worklog for triage",
        attributes,
        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. 

Morgan Stippa August 17, 2016

Okay, thanks a lot Jonny! 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events