How can I restrict group picker to certain groups? Edited

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?

1 answer

0 vote
Mizan Community Champion Oct 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)

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

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...

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 6 hours ago in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

85 views 4 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you