How to make a field unhidden depending on a condition

Karl Samson
Contributor
December 19, 2024

Hi All, I'm trying to make two fields appear for editing, if the 'Planned' date is before the 'Actual' date.

Fields:- 'Reason for Delay' (Dropdown)

             'Explanation of Delay' (Free form text).

Is there a way using ScriptRunner and 'Field Behaviours' that I could code the Server side condition to represent this?

 

Thanks.

1 answer

0 votes
Shiva Kumar Hiremath
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 19, 2024

Hello Karl samson,

you can use behaviours in script runner Create a New Behaviour select the project and issue type.
Add Fields to the Behaviour:
Add the ‘Planned’ date, ‘Actual’ date, ‘Reason for Delay’, and ‘Explanation of Delay’ fields to the behaviour use the code

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor

@BaseScript FieldBehaviours behaviours

def plannedDateField = getFieldByName("Planned Date")
def actualDateField = getFieldByName("Actual Date")
def reasonForDelayField = getFieldByName("Reason for Delay")
def explanationOfDelayField = getFieldByName("Explanation of Delay")

def plannedDate = plannedDateField.getValue() as Date
def actualDate = actualDateField.getValue() as Date

if (plannedDate && actualDate && plannedDate.before(actualDate)) {
reasonForDelayField.setHidden(false)
reasonForDelayField.setRequired(true)
explanationOfDelayField.setHidden(false)
explanationOfDelayField.setRequired(true)
} else {
reasonForDelayField.setHidden(true)
reasonForDelayField.setRequired(false)
explanationOfDelayField.setHidden(true)
explanationOfDelayField.setRequired(false)
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.12.15
TAGS
AUG Leaders

Atlassian Community Events