YouTrack InCloud 2017.3 Help

Duplicates

This workflow provides several options for managing duplicate issues.

Use Case

This workflow supports several different use cases that help you automatically process duplicate issues.

  • Prevent users from deleting a duplicates link from an issue in a Duplicate state.
  • Ensure that all issues with a Duplicate state are linked to a duplicated issue.
  • Automatically change the issue state to Duplicate when a duplicates link is added.
  • Raise the priority of an issue when a duplicates link is added.
  • Attach duplicates links to a single issue instead of creating duplicates of duplicate issues.

Modules

This workflow includes several different rules that can be applied to manage duplicate issues.

Attach duplicate links to single duplicated issue

The first rule automatically attaches duplicate issues to a single issue. This prevents users from creating a duplicates 'tree' and consolidates all duplicates links in a single issue.

var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Attach duplicate links to single duplicated issue'), guard: function(ctx) { var issue = ctx.issue; return issue.links.duplicates.isChanged || issue.links['is duplicated by'].isChanged || issue.isChanged('duplicateCluster'); }, action: function(ctx) { var issue = ctx.issue; var duplicateRoot = issue.duplicateRoot; if (duplicateRoot !== null) { issue.links.duplicates.clear(); if (issue !== duplicateRoot) { issue.links.duplicates.add(duplicateRoot); duplicateRoot.links.duplicates.clear(); } } }, requirements: { Duplicate: { type: entities.IssueLinkPrototype, outward: 'is duplicated by', inward: 'duplicates' } } });

Raise priority when issue is duplicated by another issue

The next rule attempts to raise the priority of an issue when it is duplicated by one or more issues. If a duplicate issue has a higher priority than the issue it duplicates, the priority of the original issue is raised.

var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Raise priority when issue is duplicated by another issue'), guard: function(ctx) { return ctx.issue.links['is duplicated by'].added.isNotEmpty() && ctx.issue.fields.Priority !== null; }, action: function(ctx) { var issue = ctx.issue; var currentPriorityOrdinal = issue.fields.Priority.ordinal; issue.links['is duplicated by'].added.forEach(function(added) { if (added.project !== issue.project && added.project.findFieldByName(ctx.Priority.name).values.first !== ctx.Priority.values.first) { return; } if (added.fields.Priority !== null && added.fields.Priority.ordinal < currentPriorityOrdinal) { issue.fields.Priority = added.fields.Priority; currentPriorityOrdinal = issue.fields.Priority.ordinal; } }); }, requirements: { Priority: { type: entities.EnumField.fieldType }, Duplicate: { type: entities.IssueLinkPrototype, outward: 'is duplicated by', inward: 'duplicates' } } });

Reopen issue when all duplicates links are removed

The next rule automatically changes the issue state from Duplicate to Open if there are no duplicates links attached to the issue.

var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Reopen issue when all duplicates links are removed'), guard: function(ctx) { var issue = ctx.issue; return issue.fields.State.name === ctx.State.Duplicate.name && issue.links.duplicates.removed.isNotEmpty() && issue.links.duplicates.isEmpty(); }, action: function(ctx) { ctx.issue.fields.State = ctx.State.Open; }, requirements: { State: { type: entities.State.fieldType, Duplicate: {}, Open: {} }, Duplicate: { type: entities.IssueLinkPrototype, outward: 'is duplicated by', inward: 'duplicates' } } });

Set state to "Duplicate" when duplicates link is added to issue

The next rule automatically changes the issue state to Duplicate when a user adds a duplicates link.

When an issue is updated, this rule checks that the list duplicates links is not empty and the state of this issue is not Duplicate. If a duplicates link is added and the issue state is not Duplicate, the rule verifies that the user has permission to update the State field. If the user has sufficient permission, the issue state is set to Duplicate.

var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Set state to "Duplicate" when duplicates link is added to issue'), guard: function(ctx) { return ctx.issue.links.duplicates.added.isNotEmpty() && ctx.issue.fields.State !== ctx.State.Duplicate; }, action: function(ctx) { if (ctx.issue.canBeWrittenBy(ctx.State.name, ctx.currentUser)) { ctx.issue.fields.State = ctx.State.Duplicate; } }, requirements: { State: { type: entities.State.fieldType, Duplicate: {} }, Duplicate: { type: entities.IssueLinkPrototype, outward: 'is duplicated by', inward: 'duplicates' } } });

Require links to duplicate issue when state becomes "Duplicate"

The next rule forces users to add a link to a duplicated issue when they change an issue state to Duplicate.

When issue is updated, this rule verifies that the issue state is changed to Duplicate. If the state is changed to Duplicate and the list of duplicates-type links is empty, the user is notified to add a link to a duplicated issue.

var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Require links to duplicate issue when state becomes "Duplicate"'), guard: function(ctx) { return ctx.issue.fields.becomes(ctx.State, ctx.State.Duplicate); }, action: function(ctx) { ctx.issue.required('duplicates', workflow.i18n('Add link to duplicate issue.')); }, requirements: { State: { type: entities.State.fieldType, Duplicate: {} }, Duplicate: { type: entities.IssueLinkPrototype, outward: 'is duplicated by', inward: 'duplicates' } } });
Last modified: 6 September 2017