You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Worklog the Time Passed since the Last Transition

Overview

Timetracker provides the ability to create worklogs with associated attributes. Use this script to log the time that has passed since the last transition, automatically as part of a workflow post function. The time you log in this way must comply with the rules and restrictions configured in the Timetracker app, such as the loggable hours per day.

Example

As a developer, I want to log the amount of time that has passed since the last transition automatically when I move an issue to another status. This way, I know how long the job in that status took and I don't need to log work manually.

Good to Know

Requirements

  • Jira Jira (8.0 - 8.6)
  • ScriptRunner for Jira ScriptRunner for Jira (5.6.14)
    
import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import org.everit.jira.timetracker.service.WorklogService import java.time.Instant import java.time.temporal.ChronoUnit @WithPlugin("org.everit.jira.timetracker.plugin") @PluginModule WorklogService worklogService def changeHistoryManager = ComponentAccessor.changeHistoryManager // Get the time of the last transition and the current time def timeLastTransition = changeHistoryManager.getChangeItemsForField(issue, 'status')?.last()?.created final currentTime = Instant.now() // Get the time since the last transition in minutes def timeToLog = ChronoUnit.MINUTES.between(timeLastTransition.toInstant(), currentTime) // Define optional worklog attributes (case sensitive) def worklogAttributes = ['billable'] // Create the worklog with the following paramters: issue key, duration, start date, comment, attributes // The worklog will be created by the logged in user def worklogCreateFailed = worklogService.createWorklog(issue.key, "${timeToLog}m", Instant.now(), 'PostFunction Worklog', worklogAttributes) if (!worklogCreateFailed.empty) { log.error("Worklog creation failed: ${worklogCreateFailed}") }
Discovered an issue? Report it here

Suggested for you

Appears in these Collections