0

I have a (correctly working) workflow script starting with this guard function:

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

exports.rule = entities.Issue.action({
  title: 'Create default subtasks',
  command: 'tt-create-subtasks',
  guard: function(ctx) {
    return ctx.issue.fields.Type.name == 'User Story';
  },

I thought I would replace that with something like

return ctx.issue.fields.Type == UserStory;

and therefore change the requirements from:

requirements: {
  Type: {
    type: entities.EnumField.fieldType,
    Task: {},
  }
}

to:

requirements: {
  Type: {
    type: entities.EnumField.fieldType,
    Task: {},
    UserStory: {
      name: 'User Story'
    }
  }
}

Task is used elsewhere in a similar fashion and that works:

newIssue.fields.Type = ctx.Type.Task;

But the editor gives red errors on UserStory in the giard function. Am I doing something wrong in the requirements?

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144

1 Answers1

1

If you declare the requirements like you described

requirements: {
  Type: {
    type: entities.EnumField.fieldType,
    Task: {},
    UserStory: {
      name: 'User Story'
    }
  }
}

you'll be able to check the value the following way: issue.fields.is(ctx.Type, ctx.Type.UserStory).

Alex.V
  • 2,081
  • 14
  • 13
  • That works. It does not make the code more readable though, and ultimately this still references a string value, so I'll stick with my earlier code. – Jan Doggen Apr 14 '21 at 10:07