Interface BPMInstanceClient

interface BPMInstanceClient {
    addAttachments: ((instanceId, recs) => string[]);
    cancel: ((instID, reason?) => Dict);
    delete: ((instanceId) => void);
    deleteAttachments: ((instanceId, idList) => void);
    getJumpableElements: ((instanceId) => Set<string>);
    getVars: ((instanceId, names) => Dict);
    jumpToElement: ((instanceId, name) => void);
    query: ((instanceId, options?) => Dict);
    queryActiveList: ((queryCondition?) => Dict[]);
    queryAttachments: ((instanceId, options?) => Dict[]);
    queryByCondition: ((condition?) => Dict[]);
    queryComments: ((instanceId, options?) => Dict[]);
    queryHistory: ((instanceId, category?, options?, sources?, kinds?) => Dict[]);
    queryList: ((stateCondition?) => Dict[]);
    queryMyList: ((options?) => Dict[]);
    queryProcessTasks: ((instanceId, options?) => "bp".Process[]);
    querySuspendList: ((queryCondition?) => Dict[]);
    queryTasks: ((instanceId, states?, options?) => Dict[]);
    restart: ((instID, reason?, inputs?) => FlowInstance);
    resume: ((instanceId) => FlowInstance);
    revokePreTask: ((instID, taskID?, allowClose?, create?) => FlowInstance);
    rollBackPreTask: ((instID, taskID?, allowClose?, create?) => FlowInstance);
    setVars: ((instanceId, inputs) => void);
    start: ((name, version, inputs) => FlowInstance);
    suspend: ((instanceId) => FlowInstance);
    terminate: ((instanceId, reason?) => void);
}

Properties

addAttachments: ((instanceId, recs) => string[])

为运行BPM实例添加文件附件

Type declaration

    • (instanceId, recs): string[]
    • Parameters

      • instanceId: string

        BPM实例ID

      • recs: Dict[]

        添加文件信息的记录,需要符合attachfile表的字段要求

      Returns string[]

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.addAttachments("002N000000VwBrSDISbQ", [
{
"name": "aaa",
"fileName": "a/b/c",
"category": "xxx",
"url": "xxx.com/xxx/xxx",
"taskID": "xxx",
},
{
"name": "bbb",
"fileName": "a/b/c/d",
"category": "yyy",
"url": "yyy.com/yyy/yyy",
"taskID": "yyy",
}
])
console.log(res)

Returns

添加成功的文件附件信息的记录id列表

cancel: ((instID, reason?) => Dict)

撤销BPM流程实例

Type declaration

    • (instID, reason?): Dict
    • Parameters

      • instID: string

        BPM实例ID,若ID不存在会报错

      • Optional reason: string

        撤销原因,可选

      Returns Dict

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.cancel("002N000000VwBrSDISbQ", "my reason")

Returns

BPM实例运行状态信息

delete: ((instanceId) => void)

删除BPM实例以及相关资源

Type declaration

    • (instanceId): void
    • Parameters

      • instanceId: string

        BPM实例ID,若ID不存在会报错

      Returns void

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.delete("bpInstanceId")
deleteAttachments: ((instanceId, idList) => void)

为运行BPM实例删除文件附件

Type declaration

    • (instanceId, idList): void
    • Parameters

      • instanceId: string

        BPM实例ID

      • idList: string[]

        需要删除的文件附件记录id列表

      Returns void

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.deleteAttachments("002N000000VwBrSDISbQ", ["10gh000000VwbArnQ75E"])
getJumpableElements: ((instanceId) => Set<string>)

获取可跳转的元素列表。

Type declaration

    • (instanceId): Set<string>
    • Parameters

      • instanceId: string

        BPM实例ID

      Returns Set<string>

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let recs = instClient.getJumpableElements("002N000000VwBrSDISbQ")
console.log(recs)

目前仅支持以下节点的跳转:

  1. 无法跨子流程回退 即无法回退到流程外的节点,无法回退第一个节点。具体来说,分为 3 个子场景限制:
    1. 并行网关场(AppCube BPM 中每个并行分支为一个子流程)
      1. 第一个节点无法回退,即无法回退并行任务;
      2. 并行网关内的节点无法回退到并行网关外;
      3. 并行网关外的节点无法跳转到并行网关内;
    2. 内嵌子流程场景:不能跳转到外部节点,外部节点无法跳转到内部;
    3. 调用活动场景:不能跳转到调用活动外的流程,外部节点无法跳转到内部。
  2. 只能跳转到人工节点。

确定流程实例的方法主要通过任务的 parentId 确定。对于会签来说,需要获取个人任务的父任务(会签任务)的 parentId 才能确定。

Returns

可跳转的元素列表

{
"task1": true,
"task2": true
}
getVars: ((instanceId, names) => Dict)

获取BPM实例相关的变量值

Type declaration

    • (instanceId, names): Dict
    • Parameters

      • instanceId: string

        BPM实例ID

      • names: string[]

        想查询的变量名清单,如果填入空数组,则查询所有变量

      Returns Dict

Example


import * as bp from 'bp'
let instClient=bp.newInstanceClient()
let vars = instClient.getVars("002N000000VwBrSDISbQ", ["foo", "bar"])
console.log(vars)

Returns

查询出的变量值

jumpToElement: ((instanceId, name) => void)

关闭当前任务并跳转到指定名称的任务。

Type declaration

    • (instanceId, name): void
    • Parameters

      • instanceId: string

        BPM实例ID

      • name: string

        用户任务的名称

      Returns void

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.jumpToElement("002N000000VwBrSDISbQ", "task1")

See

getJumpableElements 获取可跳转节点列表

query: ((instanceId, options?) => Dict)

查询具体BPM实例状态信息

Type declaration

    • (instanceId, options?): Dict
    • Parameters

      • instanceId: string

        BPM实例ID

      • Optional options: OptionItem

        可选参数,可部分留空或全部留空

      Returns Dict

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.query("002N000000VwBrSDISbQ", {
fields: ["name", "bpStatus", "createdDate", "owner"],
})
console.log(res)

Returns

BPM实例状态信息

queryActiveList: ((queryCondition?) => Dict[])

查询激活状态的bpm实例(激活状态是指以下几种状态"New"、"Waiting for user interaction"、"Waiting for page event"、"Paused"、"Dispatched")

Type declaration

    • (queryCondition?): Dict[]
    • Parameters

      • Optional queryCondition: QueryCondition

        查询条件,可部分留空或全部留空

      Returns Dict[]

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let recs = instClient.queryActiveList({
owner: "10gd000000KMFW1lhYZ6",
options: {
fields: ["name", "bpStatus", "createdDate", "owner"],
}
})
console.log(recs)

Returns

查询出BPM实例的记录

queryAttachments: ((instanceId, options?) => Dict[])

查询BPM运行实例的文件附件记录

Type declaration

    • (instanceId, options?): Dict[]
    • Parameters

      • instanceId: string

        BPM实例ID

      • Optional options: OptionItem

        可选参数,可部分留空或全部留空

      Returns Dict[]

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let recs = instClient.queryAttachments("002N000000VwBrSDISbQ", {
fields: ["taskID", "name", "fileName", "url"],
limit: 5,
})
console.log(recs)

Returns

多条关于指定BPM实例的文件附件信息

queryByCondition: ((condition?) => Dict[])

按自定condition和option来查询BPM实例

Type declaration

    • (condition?): Dict[]
    • Parameters

      • Optional condition: "bp".ConditionOption

        指定的查询条件,若不指定具体condition或option留空即可

      Returns Dict[]

Example


import * as bp from 'bp'
import * as db from 'db'
let instClient = bp.newInstanceClient()
let res = instClient.queryByCondition({
condition: {
conjunction: db.Conjunction.AND,
conditions: [
{
field: "createdDate",
operator: db.Operator.gt,
value: "2019-08-01 00:00:00"
}
]
},
options: {
fields: ["name", "state", "version", "bpStatus", "createdDate"],
orderby: [
{
field: "name",
order: db.Order.desc
}
],
}
})
console.log(res)

Returns

查询出BPM实例的记录

queryComments: ((instanceId, options?) => Dict[])

查询BPM实例相关的评论

Type declaration

    • (instanceId, options?): Dict[]
    • Parameters

      • instanceId: string

        BPM实例ID

      • Optional options: OptionItem

        可选参数,可部分留空或全部留空

      Returns Dict[]

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.queryComments("bpInstanceId")

Returns

BPM实例的评论记录

queryHistory: ((instanceId, category?, options?, sources?, kinds?) => Dict[])

查询BPM实例的历史记录

Type declaration

    • (instanceId, category?, options?, sources?, kinds?): Dict[]
    • Parameters

      • instanceId: string

        BPM实例ID

      • Optional category: string

        可选参数,指定查询历史的category,可以留空或置为undefined

      • Optional options: OptionItem

        可选参数,可部分留空或全部留空

      • Optional sources: string[]

        可选参数,历史记录的产生来源,用来根据数据来源筛选查询的历史记录。 Process: BPM流程实例上报的历史日志 UserTask: 用户任务图元上报的历史日志 CallActivity: 调用其他BPM流程图元上报的历史日志 Wait: 事件等待图元上报的历史日志 Task: 代办任务实例上报的历史日志

      • Optional kinds: string[]

        流程、任务状态。用于BPM历史记录查询接口,用来根据状态筛选历史日志。 created: 流程、图元或者任务创建/启动 completed: 流程、图元或者任务正常完成 suspended: 流程或者任务被挂起 resumed: 流程或者任务被恢复 terminated: 流程或者任务被终止 canceled: 流程或者任务被取消/撤回 delegated: 任务被委托 claimed: 任务(分配群组的)被认领 transferred: 任务被转移

      Returns Dict[]

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.queryHistory("002N000000VwBrSDISbQ", undefined, {
fields: ["name", "bpStatus", "category", "owner"],
}, ["Process","UserTask"], ["created", "completed"])
console.log(res)

Returns

多条关于指定BPM实例的历史记录

queryList: ((stateCondition?) => Dict[])

按指定条件查询BPM实例

Type declaration

    • (stateCondition?): Dict[]
    • Parameters

      • Optional stateCondition: StateCondition

        查询条件,可部分留空或全部留空,其中states参数可使用预定义枚举值

      Returns Dict[]

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let recs = instClient.queryList({
creator: "10gd000000KMFW1lhYZ6",
states: [
bp.State.New,
bp.State.Suspended,
bp.State.Dispatched,
]
})
console.log(recs)

Returns

返回BPM实例记录

queryMyList: ((options?) => Dict[])

查询属主是调用者本人的bpm实例

Type declaration

    • (options?): Dict[]
    • Parameters

      • Optional options: OptionItem

        查询设置,可为空

      Returns Dict[]

Example


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

Returns

查询出BPM实例的记录

queryProcessTasks: ((instanceId, options?) => "bp".Process[])

查询BPM实例任务流程列表

Type declaration

    • (instanceId, options?): "bp".Process[]
    • Parameters

      • instanceId: string

        BPM实例ID

      • Optional options: DisplayOption

        可选参数,设置返回结构,默认为tree树形结构

      Returns "bp".Process[]

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.queryProcessTasks("002N000000VwBrSDISbQ", {"mode": "tree", "type": "all"})
console.log(res)

Returns

多条关于指定BPM实例的任务执行流程

querySuspendList: ((queryCondition?) => Dict[])

查询suspended状态的bpm实例, 示例与queryActiveList类似

Type declaration

    • (queryCondition?): Dict[]
    • Parameters

      • Optional queryCondition: QueryCondition

        查询条件,可部分留空或全部留空

      Returns Dict[]

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res=instClient.querySuspendList({
owner: "10gd000000KMFW1lhYZ6",
options: {
fields: ["name", "bpStatus", "createdDate", "owner"],
}
})

Returns

查询出BPM实例的记录

queryTasks: ((instanceId, states?, options?) => Dict[])

查询一个BPM实例所对应的任务列表

Type declaration

    • (instanceId, states?, options?): Dict[]
    • Parameters

      • instanceId: string

        BPM实例ID

      • Optional states: string[]

        指定要查询任务的状态,可使用枚举值,如不指定具体内容可留空或写为undefined

      • Optional options: OptionItem

        可选参数,可部分留空或全部留空

      Returns Dict[]

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.queryTasks("002N000000VwBrSDISbQ", [bp.State.Terminated, "Closed"], {
fields: ["name", "owner", "state"]
})
console.log(res)
restart: ((instID, reason?, inputs?) => FlowInstance)

重置BPM流程实例。即撤销正在执行的流程实例并重新启动

Type declaration

    • (instID, reason?, inputs?): FlowInstance
    • Parameters

      • instID: string

        BPM实例ID,若ID不存在会报错

      • Optional reason: string

        撤销原因,可选

      • Optional inputs: Dict

        需要修改的流程变量值,可选

      Returns FlowInstance

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.restart("002N000000VwBrSDISbQ", "my reason", {
"foo": 1,
"bar": 3
})

Returns

BPM实例运行状态信息

resume: ((instanceId) => FlowInstance)

恢复一个suspended状态的BPM实例

Type declaration

    • (instanceId): FlowInstance
    • Parameters

      • instanceId: string

        BPM实例ID,若ID不存在会报错,若该实例非suspended状态,则无返回

      Returns FlowInstance

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.resume("002N000000VwBrSDISbQ")
console.log(res)

Returns

BPM实例运行状态信息

revokePreTask: ((instID, taskID?, allowClose?, create?) => FlowInstance)

撤回用户任务

Type declaration

    • (instID, taskID?, allowClose?, create?): FlowInstance
    • Parameters

      • instID: string

        BPM实例ID,若ID不存在会报错

      • Optional taskID: string

        task实例ID,若task已完成,则可以不填写

      • Optional allowClose: boolean

        是允许撤回已完成task

      • Optional create: boolean

        是否重新创建撤回节点的上一个节点

      Returns FlowInstance

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.revokePreTask("002N000000VwBrSDISbQ", "002Q000000VwBrSDISbQ",true,true)

Returns

BPM实例运行状态信息

rollBackPreTask: ((instID, taskID?, allowClose?, create?) => FlowInstance)

打回用户任务

Type declaration

    • (instID, taskID?, allowClose?, create?): FlowInstance
    • Parameters

      • instID: string

        BPM实例ID,若ID不存在会报错

      • Optional taskID: string

        task实例ID,若task已完成,则可以不填写

      • Optional allowClose: boolean

        是允许打回已完成task

      • Optional create: boolean

        是否重新创建打回节点的上一个节点

      Returns FlowInstance

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.rollBackPreTask("002N000000VwBrSDISbQ", "002Q000000VwBrSDISbQ",true,true)

Returns

BPM实例运行状态信息

setVars: ((instanceId, inputs) => void)

设置BPM实例相关的变量值

Type declaration

    • (instanceId, inputs): void
    • Parameters

      • instanceId: string

        BPM实例ID

      • inputs: Dict

        参数key-value键值对,注意设置的变量名是BPM定义过的变量

      Returns void

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.setVars("002N000000VwBrSDISbQ", {
"foo": "aaa",
"bar": "bbb"
})
start: ((name, version, inputs) => FlowInstance)

启动一个BPM实例

Type declaration

    • (name, version, inputs): FlowInstance
    • Parameters

      • name: string

        BPM名

      • version: string

        版本号,如"1.0.1"

      • inputs: Dict

        入参,如无入参,可放置空Map{}

      Returns FlowInstance

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.start("test", "1.0.1", {
"foo": 1,
"bar": 3
})
console.log(res)

Returns

BPM实例运行状态信息

{
"name": "test",
"version": "1.0.1",
"id": "002N000000VwAuoT0WjA",
"processDefID": "001L000000VBjcAIJjGa",
"interviewLabel": "test",
"nextElem": "userTask",
"isTest": true,
"state": "Dispatched",
"bpStatus": "新建",
...
...
}
suspend: ((instanceId) => FlowInstance)

暂停一个运行的BPM实例

Type declaration

Example


import * as bp from 'bp'
let instClient = bp.newInstanceClient()
let res = instClient.suspend("002N000000VwBrSDISbQ")
console.log(res)

Returns

BPM实例运行状态信息

terminate: ((instanceId, reason?) => void)

终结一个BPM实例以及相关资源

Type declaration

    • (instanceId, reason?): void
    • Parameters

      • instanceId: string

        BPM实例ID,若ID不存在会报错

      • Optional reason: string

        可选参数,终结实例原因,不写可留空或写undefined

      Returns void

Example

import * as bp from 'bp'
let instClient = bp.newInstanceClient()
instClient.terminate("bpId","bp is end")