YouTrack Standalone 2020.6 Help

Replace Links

This workflow checks the list of linked issues when a new link type is added and replaces existing links to an issue if another link type is used.

Name

@jetbrains/youtrack-workflow-replace-links

Auto-attached

no

Modules

Replace existing link when a link that uses a different link type is added to the same issue (on-change rule)

Use Case

This workflow prevents you from having two different link types for the same issue, which can create a conflict in your process.

Modules

This on-change rule checks the list of linked issues for a link to an issue that is added as a link when the issue is updated. If the new link is duplicated by a link to the same issue with a different link type, the link is replaced with the link specified in the update.

var entities = require('@jetbrains/youtrack-scripting-api/entities'); var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); function hasAddedLinks(links) { return links && links.added && links.added.isNotEmpty(); } exports.rule = entities.Issue.onChange({ title: workflow.i18n('Replace existing link when a link that uses a different link type is added to the same issue'), action: function(ctx) { var issue = ctx.issue; var relatesTo = issue.links['relates to']; var duplicates = issue.links.duplicates; var isDuplicated = issue.links['is duplicated by']; var dependsOn = issue.links['depends on']; var isRequiredFor = issue.links['is required for']; var subtasks = issue.links['subtask of']; var parent = issue.links['parent for']; var allLinks = [duplicates, isDuplicated, relatesTo, dependsOn, subtasks, isRequiredFor, parent]; function cleanup(target) { if (hasAddedLinks(target)) { target.forEach(function(issue) { allLinks.filter(function(link) { return link && link !== target; }).forEach(function(links) { links.delete(issue); }); }); } } if (hasAddedLinks(duplicates) || hasAddedLinks(relatesTo) || hasAddedLinks(dependsOn) || hasAddedLinks(subtasks)) { cleanup(duplicates); cleanup(relatesTo); cleanup(subtasks); cleanup(dependsOn); } } });
Last modified: 30 March 2021