Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set the components to show only few values using groovy script

avinashp June 17, 2019

I am trying to show only few values in the components field using behaviours on the create issue screen. Can anyone help with the Initialiser script ?  

2 answers

1 accepted

2 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2019

This short example limits the list of components in the issue screen to only the components that are less than 5 characters in length:

import com.atlassian.jira.component.ComponentAccessor

def allComponents = ComponentAccessor.projectComponentManager.findAllForProject(issueContext.projectId)
def componentField = getFieldById('components')

def allComponentAsMap = allComponents.collectEntries{["$it.id":it.name]}
def smallComponents = allComponentAsMap.findAll{it.value.length() <5}
componentField.setFieldOptions( smallComponents)
avinashp June 18, 2019

Thanks @PD Sheehan  i was struggling to get the collect entries statement. 

This really helps. Appreciate it. 

1 vote
avinashp June 18, 2019

For defining different components 

 

import com.atlassian.jira.component.ComponentAccessor

def allComponents = ComponentAccessor.projectComponentManager.findAllForProject(issueContext.projectId)
def componentField = getFieldById('components')

def allComponentAsMap = allComponents.collectEntries{["$it.id":it.name]}
def smallComponents = allComponentAsMap.findAll{it.value in ["acomponent", "bcomponent"]}
componentField.setFieldOptions( smallComponents)

Asha Goyal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2023

Thanks @avinashp It helped.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events