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:
20841
), and the Epic Link field (ID: 11440
).
Requirement:
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!
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
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.