Reputation: 11
I want to make a workflow script that will template the issue depending on the type of issue. Now my script looks like this, but it doesn't work, what could be the problem?
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
title: workflow.i18n('Insert default description template for external users'),
guard: function(ctx) {
var issue = ctx.issue;
return !issue.isReported && !issue.becomesReported && issue.description === null;
},
action: function(ctx) {
var issue = ctx.issue;
if(issue.fields.becomes(ctx.Type, ctx.Type.Bug))
{
ctx.issue.description = workflow.i18n("### **Initial state:**") +
"\n\n" +
workflow.i18n('### **Steps to reproduce:**') +
"\n1.\n2.\n3.\n\n" +
workflow.i18n("### **Expectations:**") +
"\n\n" +
workflow.i18n("### **Actual:**") +
"\n";
}
if(issue.fields.becomes(ctx.Type, ctx.Type.Task))
{
ctx.issue.description = workflow.i18n("### **Some text:**");
}
if(issue.fields.becomes(ctx.Type, ctx.Type.Feature))
{
ctx.issue.description = workflow.i18n("### **Some text:**");
}
},
requirements: {}
});
Upvotes: 1
Views: 2685
Reputation: 1888
You are looking for issue.fields.Type.name
, so you have to adjust your condition to ctx.issue.Type.name == "Bug"
, etc.
Sample condition for specific types:
return ["User Story", "Task", "Bug"].indexOf(ctx.issue.fields.Type.name) != -1;
Upvotes: 0
Reputation: 281
Type should be specified in the requirements if you want to pass it as a parameter like that. Otherwise, you just specify an object that doesn't exist, hence it throws an exception.
You can learn more about what's included in context (ctx) and how it works here: https://www.jetbrains.com/help/youtrack/devportal/context.html
Upvotes: 1