软件包开发
在流程流转到特定节点时自动触发一段代码逻辑。
流程触发器与 触发器 一样,也是一种特殊的微代码,主要用于编写流程流转过程中一些自定义业务逻辑,两者主要区别如下:
流程触发器文件名称以.processTrigger.js结尾,格式如下:
module.exports = {
listenTo: '流程API名称',
beforeDraftInsert: [async] Function,
afterDraftInsert: [async] Function,
beforeDraftSubmit: [async] Function,
afterDraftSubmit: [async] Function,
beforeStepSubmit: [async] Function,
afterStepSubmit: [async] Function,
cacluateNextStepUsers: [async] Function,
beforeCancel: [async] Function,
afterCancel: [async] Function,
beforeTerminate: [async] Function,
afterTerminate: [async] Function,
beforeEnd: [async] Function,
afterEnd: [async] Function,
}
其中
所有脚本函数均为无参函数,所属数据可从this中获取,this结构如下:
流程微服务提供以下 API 供调用。
如果return的是false,则中断操作,如在beforeSubmit里return false,则不执行提交操作。
afterSubmit: async function () {
const instanceName = this.instance.name,
spaceId = this.spaceId,
instanceId = this.instance._id;
let deadLine = ...;
let userIds = ...;
await this.broker.call(`WorkflowService.sendRemindSMS`, {
instanceName, deadLine, userIds, spaceId, instanceId
});
},