Type of multi-value field in the requirements

Hello,

I'm trying to create a script that will automatically add Assignees to the "Visible to" list of users. The field "Assignee" can specify multiple values. My script looks as follows:

 

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

exports.rule = entities.Issue.onChange({
    title: 'Add Assignee to the "visible to" list',
    guard: function(ctx) {
      var fs = ctx.issue.fields;
      return fs.isChanged(ctx.Assignee) && fs.Assignee;
    },
    action: function(ctx) {
      var issue = ctx.issue;
      issue.fields.Assignee.forEach(function(user) {
      issue.permittedUsers.add(user);
    });

    },
    requirements: {
      Assignee: {
        type: entities.EnumField.fieldType
      }
    }
});

 

The script doesn't work, yet there are no errors in the console. I've also tried to add to the requirements multi: true, but it doesn't help.

Any idea why this script won't work? Thanks

1 comment
Comment actions Permalink
Official comment

Hello,

Thank you for your question! This issue relates to incorrect requirements defined in your rule. If you open the Workflows page and expand your rule, you will see the following error because of an incorrect field type:

Would you please modify your code in the following manner to resolve the issue:

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

exports.rule = entities.Issue.onChange({
title: 'Add Assignee to the "visible to" list',
guard: function(ctx) {
var fs = ctx.issue.fields;
return fs.isChanged(ctx.Assignee) && fs.Assignee;
},
action: function(ctx) {
var issue = ctx.issue;
issue.fields.Assignee.forEach(function(user) {
issue.permittedUsers.add(user);
});

},
requirements: {
Assignee: {
type: entities.User.fieldType,
multi: true
}
}
});

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

Please sign in to leave a comment.