YouTrack Standalone 2017.3 Help

Stopwatch-style Work Timer

This workflow enables a timer that tracks the amount of time spent working on an issue.

Name

@jetbrains/youtrack-workflow-standalone-work-timer

Previous Title

Standalone Work Timer

Auto-attached

no

Modules

Start timer when the value for "Timer" becomes "Start" (on-change rule)
Stop timer when the value for "Timer" becomes "Stop" (on-change rule)

To enable this workflow:

  1. Enable and configure time tracking for your project.

  2. Add an enumerated field with the name Timer to your project. Add the values Start and Stop to the field.

  3. Add a date-type field with the name Timer time to your project.

  4. Attach the Work Timer workflow to your project.

Use Case

This workflow enables a timer that you can use to track the amount of time you spend working on an issue. When you stop the timer, the elapsed time is automatically added to the issue as a work item.

Modules

This workflow includes two modules.

Start timer when the value for "Timer" becomes "Start"

The first module contains an on-change rule that starts the timer.

var entities = require('@jetbrains/youtrack-scripting-api/entities'); var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Start timer when the value for "Timer" becomes "Start"'), guard: function(ctx) { return ctx.issue.fields.becomes(ctx.Timer, ctx.Timer.Start); }, action: function(ctx) { ctx.issue.fields.TimerTime = Date.now(); workflow.message(workflow.i18n('The timer is started.')); }, requirements: { Timer: { type: entities.EnumField.fieldType, Start: {} }, TimerTime: { type: entities.Field.dateType, name: 'Timer time' } } });

The second module contains an on-change rule that stops the timer. The elapsed time is added to the issue as a work item.

Stop timer when the value for "Timer" becomes "Stop"

var entities = require('@jetbrains/youtrack-scripting-api/entities'); var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Stop timer when the value for "Timer" becomes "Stop"'), guard: function(ctx) { return ctx.issue.fields.becomes(ctx.Timer, ctx.Timer.Stop) && ctx.issue.fields.TimerTime; }, action: function(ctx) { var issue = ctx.issue; if (issue.fields.oldValue(ctx.Timer).name === ctx.Timer.Start.name) { var newWorkItem = { description: workflow.i18n('The work item automatically added by the timer.'), date: Date.now(), author: ctx.currentUser, duration: issue.project.intervalToWorkingMinutes(issue.fields.TimerTime, Date.now()) }; issue.addWorkItem(newWorkItem); workflow.message(workflow.i18n('Work time added')); } else { workflow.message(workflow.i18n('Looks like the timer hasn\'t been started.')); } }, requirements: { Timer: { type: entities.EnumField.fieldType, Stop: {}, Start: {} }, TimerTime: { type: entities.Field.dateType, name: 'Timer time' } } });
Last modified: 7 March 2019