Hi all, trying to adjust visible options in the Component/s system field based on user groups.
The issue I'm running into is that compOptions returns either an empty array or null. I believe this is because the Component/s system field doesn't have options of its own, but rather pulls options for the relevant project. How do I access that project's component list as an array?
Don't mind the nitty gritty format of the code. I'll clean it up once I know it works.
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.fields.ComponentsField
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def compField = getFieldById("components")
def compOptions = compField.getFieldOptions().findAll()
//Create list of options to hide
def hideOptions = ["Software", "Other"]
//Remove options that match the names in the hideOptions list
def newOptions = compOptions.findAll() { option -> !hideOptions.contains(option) }
log.warn(compOptions)
log.warn(hideOptions)
log.warn(newOptions)
if (!Users.loggedInUser.isMemberOfGroup("Managers")){
compField.setFieldOptions(hideOptions)
}
else {
return;
}