Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,482
Community Members
 
Community Events
184
Community Groups

ScriptRunner Define specific options within a customfield based on usergroup

Hi all,

I'm trying to figure out how create a behavior script to hide specific value(s) within a single select customfield based on if a user is within a specific group.

For Example:

Within the Create screen of my issue type I have #customfield_12345 (Request Options) with {Value 1, Value 2, and Value 3}

I want to remove the ability for end users to select Value 1 if they are not within the jira-administrators user group.

Can anyone help me?

Thanks,

Mike

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023

Hi @Michael

For your requirement, you will need to use ScriptRunner's Behaviour, and you will need to add the code to the Behaviour Initialiser this time.

Below is a working sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def groupManager = ComponentAccessor.groupManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def optionManager = ComponentAccessor.optionsManager

def
developmentGroupUsers = groupManager.getUsersInGroup('Developer')
def adminGroupUsers = groupManager.getUsersInGroup('jira-administrators')

def sampleList = getFieldByName('Sample List')
def list1CustomField = customFieldManager.getCustomFieldObject(sampleList.fieldId)
def availableConfig = list1CustomField.getRelevantConfig(issueContext)
def list1Options = optionManager.getOptions(availableConfig)

def availableOptions = []

if (developmentGroupUsers.contains(loggedInUser)) {
availableOptions = ['Behaviour', 'Listener']
} else if (adminGroupUsers.contains(loggedInUser)) {
availableOptions = ['Fragment']
}

def availableOptionsList = list1Options?.collect {
it.value in availableOptions
}

sampleList.setFieldOptions(availableOptionsList)

Please note that the working sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

When a user added to the Developer group logs in, the Sample List will display the Behaviour and Listener options. However, when a user of the jira-administrators group logs in, only the Fragment option will be accessible from the Sample List.

Below is a screenshot of the Behaviour configuration for your reference:-

behaviour_config-1.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Hello again @Ram Kumar Aravindakshan _Adaptavist_

If I only wanted to check for the "jira-administrator" group and then have all other groups contain the same option, would I code it like this?:

if (developmentGroupUsers.contains(loggedInUser)) {
availableOptions = ['Behaviour', 'Listener']
} else {
availableOptions = ['Fragment']
}

def availableOptionsList = list1Options?.collect {
it.value in availableOptions
}

sampleList.setFieldOptions(availableOptionsList)

Thanks,

Mike

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 23, 2023 • edited

Hi @Michael

Yes, that approach will work just fine.

Just make sure that you are using the correct group in the if/else condition.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer