How to get value of custom field with enum (multi)?

I stacked on something which looks pretty trivial. Could you please help me to understand how to get value of enum (multi) field?

What I need to do is check if field “Dev Teams”( enum (multi) ) is set to “Doc”, and then assign the issue to a member of Doc team.

I am trying to do the following:

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

exports.rule = entities.Issue.onChange({
  title: 'assign issue if Dev Teams of task is Doc',
  guard: (ctx) => {
    if (issue.fields.Type.name == ctx.Type.Task.name) {
     console.log("Type = Task");
     const dt = issue.fields["Dev Teams"];
     console.log( "value="+dt.name);
      return true;
    }
  },
  action: (ctx) => {
               console.log("inside actions");
    const issue = ctx.issue;
// assign the issue
  },
                requirements: {
    Type: {
      type: entities.EnumField.fieldType,
      Task: {
        name: 'Task'
      },
      DevTeams: {
        name: 'Dev Teams',
        multi: true
      }
    },         
  }     
});

Unfortunately dt.name is almost undefined. 

I also found that I have to use forEach to get value of the field with multiple values, but 

dt.forEach(function (v) {
        console.log( "value="+dt.name);
});

also does not work. Could you please advise me how to get this value? Thank you.

 

0
4 comments

Hi!

Here is an example of the working code:

    issue.fields.NameOfYourField.forEach((v)=>{
    console.log(v.name);
    })

 

0

Thank you, Alisa. 

Looks like somethong wrong with requirements in my code.

    issue.fields.DevTeams.forEach((v)=>{
   console.log(v.name);
   }); 
    requirements: {
   Type: {
     type: entities.EnumField.fieldType,
     Task: {
       name: 'Task'
     },
   },    
   DevTeams: {
     type: entities.EnumField.fieldType,
     name: 'Dev Teams',
     multi: true,
   }      
 }

The name of enum (multi) I would like to get is ‘Dev Teams’. Still haven't found a glue (

This code shows nothing in console. 

0

Your last code should work. Maybe the workflow itself is not triggered at all? Please try changing the guard to return true; to check it.

0

Alisa, thank you for your support. It was my bad, I do not have test environment, so I was experimenting with ‘New Issue’, but have not actually pressed Create button to create a new issue on production env. Once I created New issue code worked properly.

0

Please sign in to leave a comment.