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