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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Change it :)
Trust in yourself
Post your script if you hit a roadblock.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.