How do to set default visibility rules for new issue?

I can't figure out how to set visibility to some group for all newly created issues. I could not find any relevant setting in the Administration section nor was I able to create a workflow rule for that.

Any ideas how it can be done? Thank you!

14 comments
Comment actions Permalink
Official comment

Hello Hugo,

I'd suggest the following rule:

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

exports.rule = entities.Issue.onChange({
  title: 'Test_visibility',
  guard: function(ctx) {
    var issue = ctx.issue;
    return issue.becomesReported; // or issue.isChanged('summary'), it's up to you to decide which condition to use
  },
  action: function(ctx) {
    ctx.issue.permittedGroup = ctx.technicaTeam; // or ctx.issue.permittedGroups.add(ctx.technicaTeam)
  },
  requirements: {
    technicaTeam: {
      type: entities.UserGroup,
      name: 'Tecnica-team'
    }
  }
});

 
Comment actions Permalink

Could you please give me some example on how to do that?

I mean a have a group, how do I set it on an issue? I guess I need to retrieve it from from the db, then assign it to the issue (or vice versa?), right? I am completely lost here and there does not seem any workflow examples on that.

Thanks!

0
Comment actions Permalink

Dmitry,

I'll try to create a sample workflow for you.

0
Comment actions Permalink

Thanks Maxim!

0
Comment actions Permalink

I found that it's impossible to set permittedGroup for now (http://youtrack.jetbrains.net/issue/JT-10747). I'll fix it and the fix should be delivered with the next bugfix release.

0
Comment actions Permalink

http://youtrack.jetbrains.net/issue/JT-2981 fixed. Should be included to the coming soon bugfix release 3.0.3. There is an attached sample to the issue.

0
Comment actions Permalink

Thanks Maxim!

So as soon as the bugfix is released our internal youtrack (jetbrains) will be updated as well?

0
Comment actions Permalink

Hi to all,

need some help.

I'm using YouTrack 2017.4, and i'm trying to define a rule to set default group on a new issue, in this case, i want the default project team.

I've try several options, but the field "visible to", continues with "All users".

This is my current option:

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

exports.rule = entities.Issue.action({
  title: 'Test_visibility',
  command: 'test_visibility',
  guard: function(ctx) {
    var issue = ctx.issue;
    return issue.permittedGroup;
  },
  action: function(ctx) {
    var issue = ctx.issue;
    if (issue.isChanged.summary){
      issue.permittedGroup = 'Tecnica-team';
    }
  },
  requirements: {
    'Tecnica-team': {
      type: entities.UserGroup,
      name: 'Tecnica-team'
    }
  }
});

Thanks for the help

 

 

0
Comment actions Permalink

Hi Alexander,

thanks for the help, unfortunately it did not work.

 

 

0
Comment actions Permalink

Sorry, I missed one more mistake in the script you originally posted, namely, it should be 'onChange' instead of 'action'. Corrected my answer.

1
Comment actions Permalink

Hi Alexander,

thanks for the help.

one of the problems I had was to expect the field to change when imput data in the summary, it only worked when I ran a test on a rule "State-machine".

Get this working, only after submit task.

This is my last code (working). :)

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

exports.rule = entities.Issue.onChange({
  title: 'Test_visibility',
  guard: function(ctx) {
    var issue = ctx.issue;
    return issue.isChanged('summary');
  },
  action: function(ctx) {
    if (ctx.issue.isChanged('summary')){
        ctx.issue.permittedGroups.add(ctx.tecnicaTeam);   
        }    
  },
  requirements: {
    tecnicaTeam: {
      type: entities.UserGroup,
      name: 'Tecnica-team'
    }
  }
});

 

Best regards

 

 

1
Comment actions Permalink

There's no need for the same check to be performed in action function, but it certainly does no harm.

Glad that it's now working for you.

2

Please sign in to leave a comment.