youtrackyoutrack-api

Why can't I access 'User story' as a type?


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?


Solution

  • 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).