Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

适用场景

在执行工作流转换时,去验证某个字段中的值是不是为固定格式的值

实现方式

在ScriptRunner 中创建 Workflow Function

Image Added


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

Image Added


选择自定义 Custom script validator

Image Added


在此处添加

Image Added

Code Block
languagejava
linenumberstrue
collapsetrue
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("请注意字段填写规范");
}