YouTrack Standalone 2019.3 Help

Update Fixed in Build

This workflow automates several use cases for the Fixed in build field.

Name

@jetbrains/youtrack-workflow-untag-on-reopen

Previous Title

Update Fixed in Build

Auto-attached

yes

Modules

Clear fixed in build when issue changes to an unresolved state (on-change rule)
Copy fixed in build to duplicate issues (on-change rule)
Set fixed in build for duplicate issues (on-change rule)

Use Case

When an issue is re-opened, any value in the Fixed in build field is removed.

Modules

This workflow includes three modules.

Clear fixed in build when issue changes to an unresolved state

When an issue is updated, this rule checks that issue is reported (not a draft) and the state is set to an unresolved value (for example, Open, In Progress, or Reopened) and that the previous state was set to a resolved value (for example, Fixed, Duplicate, or Incomplete). If true, the value is removed from the Fixed in build field.

var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.onChange({ title: 'Clear fixed in build when issue changes to an unresolved state', guard: function(ctx) { return ctx.issue.isReported && ctx.issue.becomesUnresolved; }, action: function(ctx) { ctx.issue.fields.FixedInBuild = null; }, requirements: { FixedInBuild: { name: 'Fixed in build', type: entities.Build.fieldType } } });

Copy fixed in build to duplicate issues

The next rule checks an issue when the state is set to Duplicate. If any duplicated issues have already been resolved and have a value in the Fixed in build field, the Fixed in build field for the duplicated issue is set to the value from the same field in all issues it duplicates.

When an issue is updated, the rule checks if the state is set to Duplicate and the list of linked issues with duplicates links is not empty.
If true, then for each issue in the duplicates list, the rule checks that the duplicated issue and the duplicate (current issue) belong to the same project, and the Fixed in build field of the duplicated issue is not empty.
If true, the value from the Fixed in build field for each duplicated issue is set to the value for the current issue.

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 fixed in build to duplicate issues'), guard: function(ctx) { return ctx.issue.fields.becomes(ctx.State, ctx.State.Duplicate); }, action: function(ctx) { var issue = ctx.issue; issue.links.duplicates.forEach(function(duplicate) { if (duplicate.project.name === issue.project.name && duplicate.fields[ctx.FixedInBuild.name]) { issue.fields.FixedInBuild = duplicate.fields[ctx.FixedInBuild.name]; } }); }, requirements: { FixedInBuild: { name: 'Fixed in build', type: entities.Build.fieldType }, State: { type: entities.State.fieldType, Duplicate: {} } } });

Set fixed in build for duplicate issues

The last rule checks when an issue update contains a value for the Fixed in build field. If true, then for each issue in the list of linked issues with is duplicated by links, this rule checks that both duplicate and duplicated (current) issues belong to the same project. If true then the Fixed in build value that is set for the current issue is applied to all duplicate issues.

var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.onChange({ title: 'Set fixed in build for duplicate issue', guard: function(ctx) { return ctx.issue.fields.isChanged(ctx.FixedInBuild) && ctx.issue.fields.FixedInBuild; }, action: function(ctx) { var issue = ctx.issue; issue.links['is duplicated by'].forEach(function(duplicate) { if (issue.project.name === duplicate.project.name) { duplicate.fields[ctx.FixedInBuild.name] = issue.fields.FixedInBuild; } }); }, requirements: { FixedInBuild: { name: 'Fixed in build', type: entities.Build.fieldType } } });
Last modified: 16 March 2020