Show custom field based on Component using Scriptrunner behaviours

jamila.augustine March 17, 2020

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

Suggest an answer

Log in or Sign up to answer
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.
March 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 

jamila.augustine March 24, 2020

@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.
March 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 

jamila.augustine March 25, 2020

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

Deleted user August 20, 2021

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

TAGS
AUG Leaders

Atlassian Community Events