Developer Portal for YouTrack and Hub Help

Update Fields on Issue Update

One of the most useful applications for workflows is to automate issue updates. The purpose of this automation is to make YouTrack do the dirty work for you. The workflows for the use cases on this page show you how you can update issues based on changes that are applied to the issue itself.

Apply Changes in Response to Manual Updates

You may have never realized that part of the functionality that you use on a daily basis in YouTrack is implemented with workflows. One such workflow is Subsystem Assignee, which is attached automatically to new projects.

This workflow contains one rule – Set subsystem owner as assignee for unassigned issues – which does exactly what the title says. The concept is relatively straightforward. Many organizational processes imply that each subsystem in your product has a responsible person or "owner". This person is the default Assignee for each new issue that is assigned to this Subsystem. When you designate an owner for each of your subsystems, every new issue is assigned accordingly. Here's the corresponding workflow rule:

const entities = require('@jetbrains/youtrack-scripting-api/entities'); const workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onChange({ title: 'Set subsystem owner as assignee for unassigned issues', guard: (ctx) => { return !ctx.issue.fields.Assignee && ctx.issue.fields.Subsystem; }, action: (ctx) => { const issue = ctx.issue; if ((issue.isReported && (issue.fields.isChanged(ctx.Subsystem) || issue.isChanged('project'))) || issue.becomesReported) { issue.fields.Assignee = issue.fields.Subsystem.owner; } }, requirements: { Assignee: { type: entities.User.fieldType }, Subsystem: { type: entities.OwnedField.fieldType } } }); t

This type of update is useful in a wide range of cases. Here are just a few examples:

  • Set the current user as Assignee when the issue state changes from Open to In Progress.

  • Change the issue State from Wait for reply to Open when a new comment is added.

  • Mark an issue as Fixed when the Fix versions are set.

  • Clear the Fix versions field when the issue state changes to Duplicate or Incomplete.

Apply Changes on a Set Schedule

Let’s say that you want to improve your productivity and support the Pomodoro technique in your project. There are plenty of ways to do it: set up a physical timer, use a mobile app, enable a browser extension... or you can simply enable the Pomodoro Timer workflow, which is distributed with YouTrack.

This workflow is supported by a set of additional custom fields, including Pomodoro state and Pomodoro countdown. As soon as the Pomodoro state changes to Timer's running, the Pomodoro countdown is set to 25. A scheduled rule immediately starts decreasing the value in the countdown field by 1 every minute:

const entities = require('@jetbrains/youtrack-scripting-api/entities'); const workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onSchedule({ title: 'Enable Pomodoro countdown', search: 'has: {Pomodoro countdown} AND Pomodoro countdown: -0 AND (Pomodoro state: {Timer’s running} OR Pomodoro state: {On a break})', cron: '0 * * * * ?', action: (ctx) => { const issueFields = ctx.issue.fields; issueFields['Pomodoro countdown'] -= 1; }, requirements: { 'PomodoroCountdown': { name: 'Pomodoro countdown', type: entities.Field.integerType }, 'PomodoroState': { name: 'Pomodoro state', type: entities.EnumField.fieldType } } });
Last modified: 19 June 2024