Skip to main content
Example scripts
arrow icon
To homepage
Jira
Cloud icon
Cloud

Show or hide fields conditionally based on the selection in another field

Features
Behaviours
Created 11 month(s) ago, Updated 25 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
typescript
// Retrieve the 'Opportunity' drop-down field and other relevant fields
const opportunityField = getFieldById("customfield_10057");  // Replace with your actual custom field ID
const contractValueField = getFieldById("customfield_10061"); // Field for 'Contract value'
const lossReasonField = getFieldById("customfield_10060");    // Field for 'Loss reason'

// Get the current selected value from the 'Opportunity' field
const opportunityValue = opportunityField.getValue()?.value;

// Control visibility based on the selected value
if (opportunityValue === 'Won') {
    // If 'Won' is selected, show the 'Contract value' field and hide 'Loss reason'
    contractValueField.setVisible(true);
    lossReasonField.setVisible(false);
} else if (opportunityValue === 'Lost') {
    // If 'Lost' is selected, show the 'Loss reason' field and hide 'Contract value'
    contractValueField.setVisible(false);
    lossReasonField.setVisible(true);
} else {
    // If neither 'Won' nor 'Lost' is selected, hide both fields
    contractValueField.setVisible(false);
    lossReasonField.setVisible(false);
}
Having an issue with this script?
Report it here