Can't pass a variable to permittedGroups.add function.

I am trying to set the group permission for the issue based on a custom field called "visibility department". I can't do this successfully.I am not sure if my syntax wrong or my requirement statement is not complete. Can you please help me?

Basically, whatever is the value of "visibility department", I want to use it for the ctx.issue.permittedGroups.add(gn); statement.


Complete code:

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

exports.rule = entities.Issue.onChange({
title: 'Set "Visible to" group on submit',
guard: function(ctx) {
return ctx.issue.fields.isChanged(ctx.department);

action: function(ctx) {
var gn =;
var dept = gn;

requirements: {

department: {
type: entities.EnumField.fieldType,
name: "Visibility Department",

HR_Marketing: {
type: entities.UserGroup

HR_Education: {
type: entities.UserGroup


Official comment


Since the permittedGroups property is represented as a Set of UserGroups, you cannot pass a group name as a parameter for the add method. Instead, pass a group that can be obtained with the findByName method:

var gn =;
var dept = entities.UserGroup.findByName(gn);

Alternatively, you can pass the group added to requirements directly:


I hope it will be helpful. Should you have any further questions, feel free to contact us.


Yes, it is possible to clear groups with the clear method:


You are always welcome! Should you have any further questions, feel free to contact us at any time. Have a great day!


Thank you for your response. This helps. I have a follow up question:

Is there way to clear all the previous permittedgroup entries? I couldn't find a command does that. Alternatively, I wanted to apply command for "Reset Visibility". That didn't work either. 

Is there way to do it? Thanks.


Perfect. Thank you for your help.


Please sign in to leave a comment.