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,364,971
Community Members
 
Community Events
168
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 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 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

Atlassian Community Events