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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

365 views 0 6
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