YouTrack Standalone 2018.2 Help

Subtask Inherit Subsystem

This workflow automatically updates the subsystem of a subtask to the subsystem set for a parent task.

Name

@jetbrains/youtrack-workflow-subtask-inherit-subsystem

Auto-attached

no

Modules

Copy subsystem from parent task when issue is linked as a subtask (on-change rule)
Set subsystem for subtasks when subsystem is set in parent task (on-change rule)

Use Case

This workflow helps you manage the subsystem set for tasks and subtasks.

Modules

This workflow includes two modules.

Copy subsystem from parent task when issue is linked as a subtask

This rule checks a subtask when it is linked to a parent task.

  • If the subtask belongs to a different project from the parent task and the projects use different sets of values for the Subsystem field, the subsystem is set for the parent task only.

  • If the subtask and parent task belong to the same project, the subsystem assigned to the parent task is set as the subsystem for any unresolved subtasks.

var entities = require('@jetbrains/youtrack-scripting-api/entities'); var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Copy subsystem from parent task when issue is linked as a subtask'), guard: function(ctx) { return ctx.issue.links['parent for'].added.isNotEmpty() && ctx.issue.fields.Subsystem; }, action: function(ctx) { var issue = ctx.issue; var safeSetSubsystem = function(subtask) { if (subtask.project && !subtask.project.isArchived) { if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.Subsystem.name)) { if (!subtask.fields.Subsystem) { var value = subtask.project.findFieldByName(ctx.Subsystem.name).findValueByName(issue.fields.Subsystem.name); if (value) { subtask.fields.Subsystem = value; } } } } }; issue.links['parent for'].added.forEach(safeSetSubsystem); }, requirements: { Subsystem: { type: entities.EnumField.fieldType }, SubtaskOf: { type: entities.IssueLinkPrototype, name: 'Subtask', outward: 'parent for', inward: 'subtask of' } } });

Set subsystem for subtasks when subsystem is set in parent task

The next rule checks for subtasks when a subsystem is set for an issue.

  • If the subtasks are in an archived project or belong to a different project from the parent issue and the projects use different sets of values for the Subsystem field, the subsystem is set for the parent task only.

  • If the subtasks are in an active project and belong to the same project as the paren task, the subsystem for each unresolved subtask is set to the subsystem set for the parent task.

var entities = require('@jetbrains/youtrack-scripting-api/entities'); var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Set subsystem for subtasks when subsystem is set in parent task'), guard: function(ctx) { return ctx.issue.fields.isChanged(ctx.Subsystem) && ctx.issue.fields.Subsystem; }, action: function(ctx) { var issue = ctx.issue; var safeSetSubsystem = function(subtask) { if (subtask.project && subtask.isReported && !subtask.project.isArchived) { if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.Subsystem.name)) { if ((issue.fields.oldValue(ctx.Subsystem) || {}).name === (subtask.fields.Subsystem || {}).name) { var value = subtask.project.findFieldByName(ctx.Subsystem.name).findValueByName(issue.fields.Subsystem.name); if (value) { subtask.fields.Subsystem = value; } } } } }; issue.links["parent for"].forEach(safeSetSubsystem); }, requirements: { Subsystem: { type: entities.EnumField.fieldType }, SubtaskOf: { type: entities.IssueLinkPrototype, name: 'Subtask', outward: 'parent for', inward: 'subtask of' } } });
Last modified: 7 March 2019