I have a case where I need to make couple of field values from the drop down visible to only 1 group and these should be hidden for other groups.
The first group can view all values but 2 should not be visible to rest of them
Please suggest
Hi @Arun,
You can achieve this through ScripRunner Behavior plugin, and below code will help you on the same
import com.onresolve.jira.groovy.user.FieldBehavioursimport com.onresolve.jira.groovy.user.FormFieldimport com.atlassian.jira.component.ComponentAccessor//Get Relevant field and options managerdef customFieldManager = ComponentAccessor.getCustomFieldManager()def optionsManager = ComponentAccessor.getOptionsManager()def groupManager = ComponentAccessor.getGroupManager()//Get select list field and it's optionsdef selectList = getFieldByName("Field Nmae") //Field name which you want to restrict valuesdef customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())def config = customField.getRelevantConfig(getIssueContext())def options = optionsManager.getOptions(config)def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()String groupName = "YourGroup" //place the group here to validateif (groupManager.getUsersInGroup(groupName).contains(user)) {def optionsMap = options.findAll {it.value in ["Value 1", "Value 2", "Value 3"] // list of options you want to show}.collectEntries {[(it.optionId.toString()): it.value]}selectList.setFieldOptions(optionsMap)}else{def optionsMap = options.findAll {it.value in ["Value 1"] // list of options you want to show}.collectEntries {[(it.optionId.toString()): it.value]}selectList.setFieldOptions(optionsMap)}
BR,
Leo
Please see below and correct me
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:Script69.groovy: 21: unexpected token: Review @ line 21, column 53., Iteration Test, State Code Review, UA^
1 error
My inputs:
import com.onresolve.jira.groovy.user.FieldBehavioursimport com.onresolve.jira.groovy.user.FormFieldimport com.atlassian.jira.component.ComponentAccessor
//Get Relevant field and options managerdef customFieldManager = ComponentAccessor.getCustomFieldManager()def optionsManager = ComponentAccessor.getOptionsManager()def groupManager = ComponentAccessor.getGroupManager()
//Get select list field and it's optionsdef selectList = getFieldByName(Phase) //Field name which you want to restrict valuesdef customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())def config = customField.getRelevantConfig(getIssueContext())def options = optionsManager.getOptions(config)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()String groupName = VRIN //place the group here to validate
if (groupManager.getUsersInGroup(groupName).contains(user)) {def optionsMap = options.findAll {it.value in [ Unit Test , Iteration Test, State Code Review, UAT ] // list of options you want to show}.collectEntries {[(it.optionId.toString()): it.value]}selectList.setFieldOptions(optionsMap)}else{def optionsMap = options.findAll {it.value in [Unit Test, Iteration Test] // list of options you want to show}.collectEntries {[(it.optionId.toString()): it.value]}selectList.setFieldOptions(optionsMap)}
Hey @Arun,
If this is your exact code, then you should try with "" in below places
1. def selectList = getFieldByName(Phase)
>>def selectList = getFieldByName("Phase")
2. String groupName = VRIN
>> String groupName = "VRIN"
3 it.value in [ Unit Test , Iteration Test, State Code Review, UAT ]
>>it.value in [ "Unit Test" , "Iteration Test", "State Code Review", "UAT" ]
4. it.value in [Unit Test, Iteration Test]
>> it.value in ["Unit Test", "Iteration Test"]
Thanks Leo, I tired the quotes and got this below
No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getFieldByName() is applicable for argument types: (java.lang.String) values: [Phase]
Please advise.
Arun
can we have something similar based on Project role instead of Group member
It looks like you're new here. Sign in or register to get started.