How do I limit components available in service desk portal

Adam.Martin March 19, 2019

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)

 

1 answer

1 accepted

0 votes
Answer accepted
Adam.Martin March 19, 2019

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") })

  

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events