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.

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.

varworkflow=require('@jetbrains/youtrack-scripting-api/workflow');varentities=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){varissue=ctx.issue;returnissue.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.

varworkflow=require('@jetbrains/youtrack-scripting-api/workflow');varentities=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){returnctx.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.