Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Scripted Validator on Radio Button

Stephen Marsh January 16, 2019

I am trying to use a simple scripted validator that will block a transition if a radio button has not been left as the default option "none".

 

The field with my radio button is field ID 10700. The default option of the field is "None" and I would like my script to pass validation, only when any radio button other than "None" has been selected.

The current behaviour is that it is correctly blocking the transition when the radio button is "None" however it is also blocking the transition when any other radio button is selected, where it should be allowed.

Can anyone shed any light where I am going wrong with my script? Many thanks

Here is my script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue

CustomField radioButton = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("10700");

if(radioButton == null)
return false

if(radioButton.getValue(issue).toString().equals("None"))
return false
else
return true

1 answer

1 accepted

1 vote
Answer accepted
Elifcan Cakmak
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.
January 17, 2019

Hello,

Could you try it like this?

import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObject("customfield_10700")

if (issue.getCustomFieldValue(customfield) == null) {
return false
} else {
return true

 I tested on script console and it works. 

Regards,

Elifcan

Stephen Marsh January 17, 2019

Excellent thank you! Works perfectly.

Like Elifcan Cakmak likes this
Raj Kumar July 18, 2019

Hi Stephen,

I have a similar requirement as yours but when I tried it didn't work from.

I want to block transition when my custom field( Radio Button id is 14403) value is "No" I want a transition to happen only when a custom field value is "Yes".

Can you please help me where I am going wrong with my script? Many thanks

Here is the script I am using.

import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObject("customfield_14403")

if (issue.getCustomFieldValue(customfield) == 'Yes') {
return false
} else {
return true
}

 

Thanks,

Raj

Karl Samson
Contributor
July 25, 2024

Hi, I want the opposite of the above. So if 'Yes' is selected in the radio button, do not allow the transition. My editor also does not like " import com.atlassian.jira.issue.MutableIssue;" saying it is not referenced when I include it in the script?

So I have:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObjectsByName("Verification?")

if (issue.getCustomFieldValue(customfield) != 'Yes') {  (Type checking errors detected in script)
return true
} else {
return false
}

Suggest an answer

Log in or Sign up to answer