适用场景
在执行工作流转换时,去验证某个字段中的值是不是为固定格式的值
实现方式
在ScriptRunner 中创建 Workflow Function

选择适用的工作流,转换动作,工作流类型

选择自定义 Custom script validator

在此处添加

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.opensymphony.workflow.InvalidInputException;
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10400L);
String str = (String) issue.getCustomFieldValue(customField);
if(str==null||"".equals(str)){
throw new InvalidInputException("请填写字段");
}
// 填写正则表达式
String regex = "^[A-Za-z]+[A-Za-z0-9_-]+";
boolean flag = str.matches(regex);
if (flag) {
} else {
throw new InvalidInputException("请注意字段填写规范");
}