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?
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@VVC let me know if you need support on that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
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.