Show or Hide Custom Field Based on Native Components with BEHAVIOURS script

What I have now shows as "Correct" but it hides the field NOWHERE. I have played around with this a lot and can only either get it to hide regardless of component or show regardless of component. The bug checker always shows a valid script...

 

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

def formComponent = getFieldById("components")
def formCapability = getFieldByName("Capability")

formComponent.getValue()

formCapability.setHidden(true)

if (formComponent.Value.toString().contains("Policy 2013"))
{
formCapability.setHidden(false)
}

else if (formComponent.Value.toString().contains("Policy 2013"))
{
formCapability.setHidden(false)
}
else formCapability.setHidden(true)

6 answers

1 accepted

0 votes
Accepted answer

Hi Lacey,

Try something like 

def formComponent = getFieldById("components")
def formCapability = getFieldByName("Capability")

def componentFieldValues = formComponent.value

if (componentFieldValues*.name?.contains("Policy 2013"))
    formCapability.setHidden(false)
else
    formCapability.setHidden(true)

regards, Thanos

Lacey,

Doe the script below works ?

nope; we have a static type checking error where no such property exists name for class java.lang.Object for "componentFieldvalues*.name?" at line 6 col 5 

 

 

There are times that is safe to ignore STC, give it a go ....

PS: Assign it to  Component/s field.

You da boss.

This works:

def formComponent = getFieldById("components")
def formCapability = getFieldByName("Capability")

def componentFieldValues = formComponent.value

if (componentFieldValues*.name?.contains("Policy 2013"))
formCapability.setHidden(false)
else if (componentFieldValues*.name?.contains("Policy 2015"))
formCapability.setHidden(false)
else
formCapability.setHidden(true)

I am facing similar challenge.  Can you please point me to where you need to insert these scripts to change the intended behavior?  I have not plug-ins installed such as Scriptrunner in my environment.

I would think this allowed out of the box configuration by Atlassian without any purchase... I can't seems to find place to enter the code in vanilla Jira.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

460 views 8 27
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you