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)

5 answers

1 accepted

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)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

176 views 0 4
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