sviklim
sviklim

Reputation: 1074

YouTrack Workflow: Prevent Deletion

I've created a very simple workflow task for a cloud based YouTrack instance. The idea is to prevent (stop workflow) deletion of issues (we'd prefer to keep all issues, even if they were submitted by mistake). The code is provided below.

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onChange({
  // TODO: give the rule a human-readable title
  title: 'When-issue-is-deleted',
  guard: function(ctx) {
    return ctx.issue.becomesRemoved;
  },
   action: function(ctx) {
     workflow.check(false, 'Do not remove issues, please');
  }
});

Though I believe it should work, when I tried to remove a new just created issue I received no error messages, and the issue was removed.

Upvotes: 3

Views: 1296

Answers (2)

ptixed
ptixed

Reputation: 441

Just in case someone else stumbles upon this issue (quoting https://youtrack.jetbrains.com/issue/JT-55220)

To make your onChange rule triggered when an issue becomes removed, you'll need to specify the runOn attribute in the rule's declaration.

runOn: {
  change: false,
  removal: true
}

Upvotes: 2

Ana Bartasheva
Ana Bartasheva

Reputation: 264

I'd recommend an easier way - just disable 'Delete issue' permission for the respective roles (https://www.jetbrains.com/help/youtrack/standalone/Create-and-Edit-Roles.html#editing_existing_roles) and users with these roles will not be able to delete issues.

As for becomesRemoved property which doesn't work properly - this is a known issue, please follow this ticket to receive further updates on it: https://youtrack.jetbrains.com/issue/JT-29303.

Upvotes: 4

Related Questions