How to Dynamically Show/Hide a Custom Field Based on Epic Link in Both Edit and View Screens?

Ashok Barik
Contributor
December 11, 2024

Hello Community,

I’m using Jira Server and need assistance with dynamically showing or hiding a custom field based on the value of the Epic Link field. Here's the scenario:

  • I have a custom field, Field A (ID: 20841), and the Epic Link field (ID: 11440).

 

Requirement:

  • If the Epic Link is empty (i.e., the Task is not linked to any Epic), Field A should be visible.
  • If the Epic Link is not empty (i.e., the Task is linked to an Epic), Field A should be hidden.

This behavior needs to work on both the Edit screen and the View screen.

I used the following ScriptRunner Behaviour:

 

def fieldA = getFieldById("customfield_20841") 
def epicLink = getFieldById("customfield_11440")
def epicLinkValue = epicLink.getValue()

if (epicLinkValue) {
fieldA.setHidden(true)
} else {
fieldA.setHidden(false)
}

This script works perfectly on the Edit screen, but it does not affect the View screen.

Any guidance or suggestions would be greatly appreciated!

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Bobby Bailey
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.
December 13, 2024

Hi @Ashok Barik , 

Unfortunately, Behaviours on DC do not impact the view screen of Issues. The only place they impact is the forms in which you make changes. 

Your field will be visible on Issue View, but not changeable. If the user tries to change a field impacted by a Behaviour, it will force the form to show, and then the Behaviour will take effect. 

Are you not able to set that field to hide when empty?

Kind regards, 

Bobby

Ashok Barik
Contributor
December 15, 2024

@Bobby Bailey 

Thank you for your response. Yes, I have tried in various ways, but I am unable to hide the field from the screen view. The problem is that the field is not empty, which is why I am unable to hide it. What I am doing now is trying to clear the field first and then hide it, but to make this take effect, I have to click the update button one more time in the Jira issue to reflect the change on the screen view.

I am using the following script in the Behaviour. Can you please take a look and let me know if we can make this change take effect in the same update? If that works, it would resolve the issue for me. Alternatively, can you suggest any other logic to hide the field or make it work as per my requirement?

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def epicLinkField = getFieldById("customfield_11440") // Epic Link field ID
def impactField = getFieldById("customfield_20841") // Impact field ID

def impactValue = """Some default value already set"""

if (!epicLinkField.value) {
impactField.setFormValue(impactValue)
impactField.setHidden(false)
impactField.setRequired(true)
} else {
impactField.setFormValue(null)
impactField.setHidden(true)
impactField.setRequired(false)
}
Bobby Bailey
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.
December 16, 2024

@Ashok Barik So, to clarify, because behaviours cannot run on the issue view, any code you write on the behaviour will not execute until you edit the issue, which is why you are running into that issue. 

I would be happy to help! I am a little unclear as to you requirement from reading the code, sorry. Could you spell out what you need for me?

Kind regards, 

Bobby

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 15, 2024

Hi @Ashok Barik

As what @Bobby Bailey has mentioned Behaviours do not work on the View screen.

You can refer to this ScriptRunner Documentation to understand the limitations of the Behaviour feature.

Thank you and Kind regards,
Ram

TAGS
AUG Leaders

Atlassian Community Events