Skip to content

BPM process library

Basic Concepts

Process processing involves many concepts. To implement some complex process processing, the internal objects of the system are designed flexibly, which may cause misunderstanding when using the system for the first time. Therefore, the process relationship diagram is as follows:

bpm_concept

First of all, let's look at the development state. There are three main concepts in the development state:

  1. Process definition, that is, the defined flow chart, generally consists of various nodes, defining how the process should flow;
  2. User task node, that is, the user task node in the flowchart, is a special node that requires special attention. When the process has reached this node, the process will continue only after the user performs the next operation feedback.
  3. Form page, that is, the definition of the form page associated with the user task node.

To make the process run, the concept of each development state is mapped to the concept of the running state.

  1. Process instance: records created from process definitions for recording process status information. One process definition can generate multiple instance records.Task instance`, which is generated by the user task node in the flow transfer and used to record the task status. One user task node may create multiple task instances. (For example, in the countersign scenario, a task instance is generated for each independent countersigner.) Therefore, a process instance can have multiple task instances.
  2. Page rendering: Each page defines a form page generated by the rendering engine of the platform. The form page can be a standard page, advanced page, or even a customized page of the platform. The main purpose is to provide interfaces for users to invoke interfaces.

The running mechanism of the flow is as follows: First, when a user starts a new flow, the system will generate a flow instance according to the flow definition information. When the flow transfers to the user task node, one or more corresponding task instances will be generated according to the definition of the user task node, and the flow will be suspended. Return to the caller, waiting for the task instance to complete. The assignor of a task instance can click the page associated with the process instance on the process to-do page and complete the task on the page. At this time, the process is restarted and activated. The remaining nodes are executed according to the process definition. The execution process of the preceding user task nodes is repeated. The process ends until no new task can be generated in the process definition.

Each process instance is created and ended.EV_FLOW_STARTEDAnd with theEV_FLOW_TERMINATEDevent, and for each task instance creation and completion, there is aEV_TASK_STARTEDAnd to theEV_TASK_TERMINATEDEvents. Developers can customize service processes by listening to these events.

The AppCube script library is also divided into two parts. One is the bpmmeta library used to build process definitions, and the other is the bp library used to operate instances. You should use the correct library as required.

Process Instance Operations

The AppCube provides rich operation capabilities for flow instances and task instances. The main interfaces are as follows:

  • bp.newInstanceClient(): Modify an instance, that is, query and modify a flow instance, for example, terminate a flow.
  • bp.newTaskClient(): performs operations on a task instance, for example, completing or stopping a task.
  • bp.newQueryTaskClient(): Perform complex query on task instances, such as querying to-do tasks and filtering task instances by condition.

And while thebp.newClientV1()This API has been marked obsolete and may not be available in the future. Do not use this API.

Some common application scenarios are listed below.

Querying to-do tasks

Querying to-do tasks refers to querying the task instances to be processed. The AppCube provides the following preconfigured interfaces for querying to-do tasks:

ts
import * as bp from 'bp';

let queryTaskClient = bp.newQueryTaskClient();
let res = queryTaskClient.queryMyLis({
  rootID: '...', //Flow instance ID.
  options: {
    fields: [
      'assignee',
      'assigneeID',
      'assigneeType',
      'assigneeName',
      'name',
      'state',
      'rootID',
      'owner',
    ],
  },
});
console.log(res.recs); //Array Result
console.log(res.total); //Statistics

Querying My Submitted Processes

Querying My Submitted Processes refers to querying the list of process instances submitted by users. The AppCube provides the following preconfigured interfaces for querying the list of process instances submitted by users:

ts
import * as bp from 'bp';

let instClient = bp.newInstanceClient();
let recs = instClient.queryMyList({
  fields: ['name', 'bpStatus', 'createdDate', 'owner'],
});
console.log(recs);

Querying historical flows

Querying historical flows refers to querying the list of completed flow instances submitted by users. The AppCube provides the following preconfigured interfaces for querying historical flows:

ts
import * as bp from 'bp';

let instClient = bp.newInstanceClient();
let recs = instClient.queryList({
  creator: '...', //User ID.
  states: [bp.State.CompletedOk],
});
console.log(recs);

This interface can also adjust the states and creator query as required to query the flow instances of different states and users.

Start Process/Create Process Instance

In general, starting a process and creating a process instance means one thing, creating a process instance from the specified process definition.

ts
import * as bp from 'bp';
let instClient = bp.newInstanceClient();
let res = instClient.start(
  'NAME', //Flow Name
  'VERSION', //Process version. If the value is left blank, the activated process version is used. Otherwise, the process is started based on the process definition of the specified version.
  {
    //Initializing and assigning values to process variables
    key: 'value',
  },
);
console.log(res);

In the preceding command, VERSION is usually specified as a null character string. In rare cases, you need to specify the version of the startup process.

To complete the task

When the process is transferred to the specified owner, the task completion interface needs to be invoked to continue the process.

ts
import * as bp from 'bp';
let taskClient = bp.newTaskClient();
let res = taskClient.complete(
  'ID', //ID of a task instance.
  'OUTCOME', //Task result, for example, approve or reject. If the result is not defined in the process, this field can be left blank.
  {
    //Assigning values to task instance variables
    key: 'value',
  },
);
console.log(res);

Process definition operation

The bpmeta library provides APIs for adding, deleting, modifying, and querying flow definitions. Currently, these APIs are being tested and may change. Exercise caution when using these APIs.