Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Show Specific Fields and Hide Existing Ones Based on Epic Link Value Using Groovy Script"

Sakshi Nema October 20, 2024

Hi Team,

How can I write a Groovy script(behaviours) that checks if the Epic Link value is equal to a certain value, and if so, makes specific fields visible while hiding the existing ones?

Please help.

Best Regards

Sakshi

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Kishan Sharma
Community Champion
October 21, 2024

Hi @Sakshi Nema 

I have tested below script on my DC instance, it works well.

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField

// Get the current form fields
def epicLinkField = getFieldById(getFieldChanged()) // Epic Link
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// Field keys to be shown or hidden
def fieldToShow = getFieldByName("Cost") // Replace with your field name to show
def fieldToHide = getFieldByName("Benefit") // Replace with your field name to hide

// Get the current value of the Epic Link field
def epicLinkValue = epicLinkField.getValue()

// Define the target epic key for the condition
def targetEpicKey = "KISHAN-07" // Replace with your Epic issue key

// If the Epic Link value matches the target key, show specific fields and hide others
if (epicLinkValue == targetEpicKey)
{
// Show certain fields
fieldToShow.setHidden(false)

// Hide the other fields
fieldToHide.setHidden(true)
}
else
{
// Default behavior: show or hide as per your requirements
fieldToShow.setHidden(false)
fieldToHide.setHidden(false)
}

In this example, its checking if the issue has KISHAN-07 as its EPIC Link, if yes, it hides Benefit field and shows Cost field, else, it shows both the fields. Hope this helps you to get started.

TAGS
AUG Leaders

Atlassian Community Events