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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,334
Community Members
 
Community Events
185
Community Groups

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')

tatr.setHidden(true)

if(values.toString().contains("test"))
{
tatr.setHidden(false)

}

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?

Thanks

1 answer

1 accepted

1 vote
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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

tatr.setHidden(true)

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

 

BR,

Leo 

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

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 {it.name.contains("test")})

 

BR,

Leo 

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

Deleted user Aug 20, 2021

@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
TAGS
AUG Leaders

Atlassian Community Events