First up, I'm not a developer; the code below is hacked from examples found online.
Problem: We have a custom field to denote the version the fix actually shipped in ("Shipped Version"). It uses the Version pick-list. For compliance reasons, we want to restrict the options available at the Resolve transition. To achieve that we'd like to have a validator which would ensure only a couple of values are valid during a particular transition (e.g. error if they select something else).
I've tried writing the following code, but it's not picking up the selection when they select the correct value.
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();
CustomField customField = customFieldManager.getCustomFieldObject("customfield_13978");
def currentValue = issue.getCustomFieldValue(customField);
if( (currentValue != 'Current' ) && (currentValue != 'Current-2' ) ) {
return false
}
else {
return true
}
I'm wondering if this is because the value of the version isn't stored as a string and thus won't compare properly. However, I'm not able to figure out how to convert it to a string or add the proper non-string id for the release into the compare (I tried entering the version ID number).
Thank you in advance for any help here!
-Brian