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

Lacey McDonnell November 3, 2016

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
Answer accepted
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2016

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

0 votes
Jay Kantaria December 3, 2018

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.

0 votes
Lacey McDonnell November 10, 2016

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)
0 votes
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2016

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

PS: Assign it to  Component/s field.

0 votes
Lacey McDonnell November 10, 2016

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 

 

 

0 votes
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2016

Lacey,

Doe the script below works ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events