How can I restrict group picker to certain groups?

Brüse, Bernhard October 10, 2017

Hi there,

in JIRA, we like to implement a group picker (single choice) in order to define the responsible development group for a new feature out of a small list stored in the internal user directory.

Instead of defining validators for every workflow steps (at least 2 different workflows are affected) we thought about using global Behaviours (Scriptrunner add-on). After checking the documentation, I tried this validator script for the according customfield, mapped to all projects and issue types:

import com.atlassian.jira.component.ComponentAccessor

def respDevTeamFld = getFieldByName("Responsible Development Team")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(respDevTeamFld.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionsToSelect = options.findAll { it.value in ["Option 1", "Option 2", "..."] }
respDevTeamFld.setFormValue(optionsToSelect*.optionId)

Unfortunatelty, it does not work. The user picker for the customfield "Responsible Development Team" is not restricted to the defined values. The user is still able to select any group stored in the internal user directory.

Do you have any idea what is wrong?

6 answers

0 votes
Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2022

Hi @Brüse, Bernhard 

Did you find the solution for this??

0 votes
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 17, 2021
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2022
0 votes
Richard Duffy February 10, 2021

Also interested in this request!  =)

0 votes
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2021

I am also looking to present users with a list of 'pre-selected' groups that they can select so that the issue is assigned to that group, instead of a single agent.

Has anyone managed this yet?

0 votes
Mario November 11, 2020

Dear @Brüse, Bernhard

have you been able to solve this problem and did you find a valid code snippet to enable the restriction of a group picker to specific values? 

Thank you very much.

Kind regards

Mario

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 10, 2017

You are trying to set the field value , I believe you should set the field options instead.

Please refer the below . Replace the id's with actual group id's

Let me know how it goes . Add logging it will become easier to develop the required script

FormField resDevTeam = getFieldByName("Responsible Development Team") 
def ops = ["-1":"None"]
ops.put("10000","group 1")
ops.put("10001","group 2")
resDevTeam.setFieldOptions(ops)
Hans-Hermann Hunfeld October 23, 2017

Hi Mizan,

just tried your suggestion, but unfortunately this doesn´t work (cannot see anything being affected)!

My script: 

import com.atlassian.jira.component.ComponentAccessor

FormField resDevTeam = getFieldByName("Responsible Development Team")
def ops = ["-1":"None"]
ops.put("10501","Pascal")
ops.put("11203","Keytech")
resDevTeam.setFieldOptions(ops)

Script checker tells me that class "FormField" is unable to resolve...

Any ideas how to get this up&running? Many thanks in advance,
Hans-Hermann

Hans-Hermann Hunfeld October 23, 2017

Maybe another idea/problem:

In the long run we want to select one or multi user groups based on a pre-defined list of existing user groups as we got some external partners working on our JIRA and we want to give them the possibility to browse and transition issues in certain cases.

AFAIK there is no option to show the user the entire list of possible options in a (multi) user group picker field itself (maybe the user doesn´t exactly know how the group is named), so i tried to manage this via a db driven field. Here i got the according list restricted to certain groups, but how to grant the according members of the choosen groups some permissions respectively use workflow conditions?

I could copy each time via event listener the db driven field to the user group field, but this sounds a bit creapy to me...

Chhaya Gadade November 2, 2018

@Hans-Hermann Hunfeld:Where should I run this script?

Suggest an answer

Log in or Sign up to answer