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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.