Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Depending on User role how to visibility for certain value in a custom field of type List(Drop dow)?

Devendar Gangapuram
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.
June 30, 2022

Hi Team,

We have List type custom feilds, I need tos how only certian values depending on the user roles in JIRA software (server instance). Is it possible to implement ? if yes, please provide me the guideline. documen tlink. 

Please see below screen shots for more clarity.

Releases List.PNG

 

2 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 1, 2022

Hi @Devendar Gangapuram

Suppose you want to handle the visibility of a particular field based on a user's role. In that case, you can use the same approach given in the Restricting Issue Type example in the Adaptavist Documentation.

The only modification you will have to do is that instead of filtering the issue type, you will need to filter the custom field.

You could try something like the sample below using the Behaviour Initialiser:-

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

@BaseScript FieldBehaviours behaviours
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def optionManager = ComponentAccessor.optionsManager

def sampleList = getFieldByName('Sample List')
def list1CustomField = customFieldManager.getCustomFieldObject(sampleList.fieldId)

def userRoles = projectRoleManager.getProjectRoles(loggedInUser, issueContext.projectObject)*.name

def availableConfig = list1CustomField.getRelevantConfig(issueContext)
def list1Options = optionManager.getOptions(availableConfig)

def availableOptions = []

if ("Users" in userRoles) {
availableOptions = ['Behaviour', 'Listener']
} else if ("Developers" in userRoles) {
availableOptions = ['Fragment']
}

def availableOptionsMap = list1Options?.findAll {
it.value in availableOptions
}?.collectEntries {
[ (it.optionId.toString()) : it.value ]
}

sampleList.setFieldOptions(availableOptionsMap)

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

I  hope this helps to solve your question. :)

Thank you Kind regards,

Ram

0 votes
Craig Nodwell
Community Champion
June 30, 2022

Hi @Devendar Gangapuram have a review of this post it is similar to what you are trying to achieve and has a script that you can modify to meet your needs.
ScriptRunner-Behaviours-change-select-list-based-on-customfield 

Devendar Gangapuram
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.
June 30, 2022

Thank you @Craig Nodwell , I have reviewed it but looks not exactly it . Below is my scenario,

--> customfield-123(Single select list) has set of values like below :
1.0.0
1.0.2
2.0.3
3.5.1
5.9.0
4.5.9
9,1.6
3.6.9
When user A logins it should show only 1.0.2, 2.0.3 & 9,1.6 and

if User B logins it should show 1.0.0, 3.6.9 , 5.9.0 & 4.5.9 ... etc

Craig Nodwell
Community Champion
June 30, 2022

Change it :)
Trust in yourself
Post your script if you hit a roadblock.

Like Devendar Gangapuram likes this

Suggest an answer

Log in or Sign up to answer