Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi,
I want to add a validation when creating an issue, the definition is to check one field (called ‘Found In’) which is a Select List (single choice) custom field, and if the value in it is A or B then check if another field has a value. The second field is a Version Picker (single version), called ‘Release’.
I tried using the script runner simple script validation, but I don’t know how to get the value of the Release field, and also how to ask for the A OR B. checking just for one works.
Can someone help with the needed validation code ?
Thanks,
Alon
Hello,
It could be like this
if (ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("A") || ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("B")) {
if (ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Release").getValue(issue).size() > 0) {
return true;
} else {
return false;
}
} else {
return true;
}
Thank you for your answer.
It didn't work as you wrote, but it pointed me in the right direction.
I think the problem was getting the value for the version picker field.
Here is what I ended up with:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
// get "Release" field
CustomField customField = customFieldManager.getCustomFieldObject("customfield_11434");
def currentValue = issue.getCustomFieldValue(customField)
// if (ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("A") || ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("single select").getValue(issue).toString().equals("B")) {
if ((cfValues['single select']?.value == 'A' ) || (cfValues['single select']?.value == 'B' )) {
if (currentValue)
{
return true ;
}
else{
return false;
}
}
else {
return true;
}
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.