Mandatory Workflow Tag

Help! I'm a marketer who somehow ended up in charge of our YouTrack. I've been trying to create a workflow to force users to add a tag when creating a ticket, and have referenced this previous post, but cannot get it to work. 

Not sure If I should be creating a new workflow & module, or what kind I should pick. The hot mess below is the closest I've come on the code, using an on-change module, modelling after the Due-Date Required workflow we have that does function.

Desired end result: When someone creates a ticket but does NOT select a tag, it gives them a little pop-up "Select one Tag: Mx-Community, Mx-External, or Mx-Internal"

Any help is appreciated.

Hot Mess of Code

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

exports.rule = entities.Issue.onChange({
title: workflow.i18n('Tag Required to Create Mx Ticket'),
guard: function(ctx) {
return ctx.issue.becomesReported;
},
action: function(ctx) {
ctx.issue.tags.required(ctx.tags, workflow.i18n('Select one Tag: Mx-Community, Mx-External, or Mx-Internal'));
},
requirements: tags.isNotEmpty {
}
});

 

4 comments
Comment actions Permalink
Official comment

Hello,

I suggest you use the workflow.check method to prevent the issue creating if there are no any tags added:

```workflow.check(ctx.issue.tags.isNotEmpty(), 'Select one Tag: Mx-Community, Mx-External, or Mx-Internal');```

Should you have any further questions, feel free to contact us.

Comment actions Permalink

Thank you so much for this Oleg, I have reduced my code to the below, but when I try to save it I receive an error, and there is a yellow dot next t line 4, which is where I have the workflow.check string line.

Error Message: Parsing or evaluation exception: syntax error (mx-tag-required/mx-tag-required-2#5)

New Code:

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


workflow.check(ctx.issue.tags.isNotEmpty(), 'Select one Tag: Mx-Community, Mx-External, or Mx-Internal');
},
requirements:{}
});

0
Comment actions Permalink

Hello Liam, 

The suggested code should be inside the action block. So, a full code should be the following:

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


exports.rule = entities.Issue.onChange({
  title: 'Tag Required to Create Mx Ticket',
  guard: function(ctx) {
    return ctx.issue.becomesReported;
  },
  action: function(ctx) {
     workflow.check(ctx.issue.tags.isNotEmpty(), 'Select one Tag: Mx-Community, Mx-External, or Mx-Internal');
  },
  requirements: {

  }
});
0
Comment actions Permalink

Thank you very much Oleg, it is now working very well.

0

Please sign in to leave a comment.