Mandatory field

Hi everyone,

I've create a custom filed that call "regarding", now I want to create a workflow that force users to fill "regarding".

I've create below workflow, and type of this workflow are "on change", then attach it to project, but after users create new issue not force users to fill "regarding" and issue will be saved!

FYI: "regarding" type is "EnumField"

any idea?

Thanks,

 

 

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

exports.rule = entities.Issue.onChange({
  // TODO: give the rule a human-readable title
  title: 'Reqmodule',
  guard: function(ctx) {
    // TODO specify the conditions for executing the rule
    return ctx.issue.becomesReported;
  },
  action: function(ctx) {
    //var issue = ctx.issue;
    // TODO: specify what to do when a change is applied to an issue
      ctx.issue.fields.required(ctx.regarding,
      workflow.i18n('You must set the regarding!'));
  },
  requirements: {
    // TODO: add requirements
    Regarding: {
      type: entities.Field.stringType,
       name: "regarding"
  }
  }
});

 

 

3 comments
Comment actions Permalink
Official comment

Hello,

First of all, mind the case: you have defined the field as 'Regarding' in requirements, but access it as 'regarding'. Besides that, you're accessing issue field. So, it should be ctx.issue.fields.Regarding.  

Second, you said Regarding is EnumField, but it is defined as a string in requirements section. Please change its type to `type: entities.EnumField.fieldType,` in requirements section. 

Please let me know if it helps.

Comment actions Permalink

Hi Dear Anastasia,

Thank you for answer, I've fix those things you've mention, but after save script Youtrack show this message "requires setup, field regarding should be a single-value"

 

 

 here is the scripts:

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

exports.rule = entities.Issue.onChange({
  // TODO: give the rule a human-readable title
  title: 'Reqmodule',
  guard: function(ctx) {
    // TODO specify the conditions for executing the rule
    return ctx.issue.becomesReported;
  },
  action: function(ctx) {
    //var issue = ctx.issue;
    // TODO: specify what to do when a change is applied to an issue
      ctx.issue.fields.required(ctx.regarding,
      workflow.i18n('You must set the regarding!'));
  },
  requirements: {
    // TODO: add requirements
    regarding: {
      type: entities.EnumField.fieldType,
       name: "regarding"
     }
  }
});
 

0
Comment actions Permalink

If this field is configured to be multi value, then just add `multi: true` to the definition of the field:

requirements: {
    // TODO: add requirements
    regarding: {
      type: entities.EnumField.fieldType,
       name: "regarding",
       multi: true
     }
  }
0

Please sign in to leave a comment.