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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.