ScriptRunner to hide/display and optional/required upon Close status and based on type field

VVC
Contributor
February 19, 2025

Need assistance with Scriptrunner code to ensure that a radio button field "Is this still occurring?" is hidden right from the start of ticket creation and irrespective of any status.

Now I need the above radio button field to be dynamically visible on the fly and mark it as required, only when the single-select "Type" field value equals "Standard" and upon status transition to Close.

But if the "Type" value changes to other than "Standard" then the radio button field must be hidden and set to optional. Is this something achievable using Script Runner?

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2025

Hi @VVC ,

yes, you can do that through a scriptrunner behaviour. Please check documentation here https://docs.adaptavist.com/sr4js/9.7.0/features/behaviours/behaviours-examples/field-required

if you have trouble on that let me know.

Fabio

VVC
Contributor
February 20, 2025

Thanks @Fabio Racobaldo _Herzum_ for sharing this documentation. TBH, what I'm looking to accomplish is using a popup screen during the workflow transition to Close status with the radio button field marked as required, only when Type field is selected as Standard.

Also, suppress or do NOT pop up any screen during the workflow transition to Close status when Type field value is NOT selected as Standard. Is this something achievable using Script Runner in combination with workflows in JIRA DC?

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2025

@VVC using a behaviour you can make a field mandatory/optional based on value of other field (both on transition screen). Unfortunately popup will always appear 

VVC
Contributor
February 20, 2025

@Fabio Racobaldo _Herzum_ That's exactly of what I was expecting as well. Hence, I had to workaround on adding this field onto the main ticket screen rather using a popup screen during workflow transition. I will give it a try using behaviors and see how it goes.

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2025

@VVC let me know if you need support on that

Like VVC likes this
VVC
Contributor
February 24, 2025

Hi @Fabio Racobaldo _Herzum_ 

I have tried adding the below behavior code by adding to the initializer as well as on the custom field "Is this Occurring?" but it doesn't seems like working.

The radioButtonField remains hidden always even after the ticket status is Installed and the Type value is Standard. Am I missing something here?

 

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

import groovy.transform.BaseScript

import com.atlassian.jira.component.ComponentAccessor

import org.apache.log4j.Logger

@BaseScript FieldBehaviours behaviours

def log = Logger.getLogger("com.onresolve.jira.groovy")

def cmrTypeField = getFieldByName("Type")

def issueStatusField = getFieldById("status")

def radioButtonField = getFieldByName("Is this Occurring?")

// Hide the radio button field by default

radioButtonField.setHidden(true)

// Check the conditions

def cmrTypeValue = cmrTypeField.getValue() as String

def issueStatusValue = issueStatusField.getValue() as String

log.debug("CMR Type: ${cmrTypeValue}")

log.debug("Issue Status: ${issueStatusValue}")

if (cmrTypeValue == "Standard" && issueStatusValue == "Installed") {

    radioButtonField.setHidden(false)

}
 
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 24, 2025

@VVC , please try the following code :

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import com.atlassian.jira.issue.Issue

@BaseScript FieldBehaviours behaviours

def log = Logger.getLogger("com.onresolve.jira.groovy")
def cmrTypeField = getFieldByName("Type")
def radioButtonField = getFieldByName("Is this Occurring?")

Issue issue = getUnderlyingIssue();

// Hide the radio button field by default
radioButtonField.setHidden(true)

// Check the conditions
def cmrTypeValue = cmrTypeField.getValue() as String
log.debug("CMR Type: ${cmrTypeValue}")
if (issue!=null && "Installed".equalsIgnoreCase(issue.getStatus().getName()) && "Standard".equalsIgnoreCase(cmrTypeValue)) {
radioButtonField.setHidden(false)
}

 

Hope this helps,

Fabio

Like VVC likes this
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events