Using scriptrunner behaviours I'm trying to limit the components users can choose in the service desk portal based on the description of those components in my project. I'm currently using the code below, but it has no effect.
import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.*
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)
getFieldById(COMPONENTS).setFieldOptions(components.findAll { it.getDescription().contains("ValidString") }*.id)
Was missing the '?' operator as blank descriptions are actually null objects. Also need to pass the full object, not just the id. The below works:
import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.*
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)
getFieldById(COMPONENTS).setFieldOptions(components.findAll { it.getDescription()?.contains("ValidString") })
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.