Skip to main content

Workflow Validator

The proxima:workflowValidator module can create a workflow validator.

workflow-validator-1

The workflow validator will determine whether the transition can proceed during the workflow transition. If the transition fails, an error will be thrown.

workflow-validator-2

Configure team expressions on workflow validator

You can configure team expressions to return the result of the validator.

For example, you can configure the following in the plugin's manifest, where expression is the expression and errorMessage is the prompt message.

modules:
proxima:workflowValidator:
- key: my-workflow-validator
title: Assignee Required Validator
description: The assignee must not be empty to transition
expression: item.values.assignee?.length > 0
errorMessage: The assignee cannot be empty

workflow-validator-3

tip

The expression can use the following properties:

  • item - [Item]
  • currentUser - [User]
  • workspace - [Workspace]
interface Item {
name: string; // item name
key: string; // item key
objectId: string; // item id
values: Record<string,any>; // item custom field value
itemType: { // item type
objectId: string;
},
status: { // item status
objectId: string
};
}

interface User {
objectId: string;
createdAt: string; // creation time
updatedAt: string; // update time
username: string; // user name
email: string;
enabled: boolean; // Whether to enable
deleted: boolean; // delete or not
nickname: string;
language: string; // language (e.g. 'zh-CN')
}

interface Workspace {
createdAt: string; // creation time
updatedAt: string; // update time
name: string; // workspace name
key: string; // workspace key
}

Configure validators through a custom UI

You can configure rules in the validator through a custom UI. The following three pages need to be configured:

  • create: The page when creating the workflow validator
  • edit: The page when editing the workflow validator
  • view: The page when displaying the workflow validator

On the create and edit pages, you need to save the configuration information through the handleWorkflowConfigChange API.

Manifest example

modules:
proxima:workflowValidator:
- key: my-workflow-validator
title: Configure Workflow Transition Validator
description: Custom workflow validator
create:
route: /workflow-validator-create
edit:
route: /workflow-validator-edit
view:
route: /workflow-validator-view
resource: main
loadType: Micro
resources:
- key: main
path: /dist

Overriding expression and errorMessage

The handleWorkflowConfigChange method can override the expression and errorMessage configured in the manifest.

import { Input } from 'antd';

const WorkflowValidatorCreatePage = (props: any) => {
const { context } = props;
const handleWorkflowConfigChange = context?.modal?.handleWorkflowConfigChange;

const onChange = (key, value) => {
handleWorkflowConfigChange({ [key]: value });
};

return (
<div>
<div>Expression:</div>
<Input placeholder="Enter expression" onChange={e => onChange('expression', e.target.value)} />
<div>Error Message:</div>
<Input placeholder="Enter error message" onChange={e => onChange('errorMessage', e.target.value)} />
</div>
);
};

export default WorkflowValidatorCreatePage;

workflow-validator-4

workflow-validator-5

Configure validators through function

You can implement the validator's validation through the application's functions.

caution

Validator can only configure either expression or function, not both simultaneously.

Manifest example

modules:
proxima:workflowValidator:
- key: my-workflow-validator
title: Workflow Transition Validator Function
description: Workflow validator validation function
function: validator-function
function:
- key: validator-function
handler: workflow.runValidator

workflow-validator-6

Function example

The function needs to return two parameters:

  • result: A boolean value indicating whether the workflow passes.
  • errorMessage: The error message that will be displayed when result=false during the transition.
workflow.ts
export const runValidator = ({ payload }) => {
const { item } = payload;
if (item?.values?.assignee?.length > 0) {
return {
result: true,
};
}
return {
result: false,
errorMessage: 'The assignee cannot be empty',
};
};