Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Show custom field based on Component using Scriptrunner behaviours

Hi I am trying to create a behaviour to show a custom field based on component value.

I have read the previous helpful articles and have the following script

def comp = getFieldById(COMPONENTS)
def values = comp.getValue()*.getName()

def tatr = getFieldById('customfield_14310')




This shows a spread operator error on line 2 (def values) and hides the custom field  no matter what.


Can someone give me a hint what could be wrong?


1 answer

1 accepted

1 vote
Answer accepted
Leo Community Leader Mar 24, 2020

Hi @jamila.augustine 

I've modified the script slightly , I haven't tested this out by myself so may require some changes

import com.atlassian.jira.bc.project.component.ProjectComponent

def component = getFieldById(getFieldChanged())
def tatr = getFieldById('customfield_14310')
List <ProjectComponent> comps = component.getValue() as List
def isthere = false


for(c in comps){
if(c.getName().contains("test")){isthere = true}




@Leo : Thanks! i tried the script..But the field "tatr" is still hidden.

Leo Community Leader Mar 24, 2020

I've tested below script and it's working, no modifications required

you'll have to place this script as server side script for Component/s field


import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def tatr = getFieldById('customfield_14310')

def components = getFieldById(getFieldChanged()).getValue() as List<ProjectComponent>
tatr.setHidden(!components.any {"test")})




@Leo : Awesome! Thank you so much. I had created an initialiser. 

@Leo Is it possible to leave the component/s field which is a mandatory field system, via scriptrunner?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

133 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you