DataSource

Description:
Source:
跨应用数据源以及连接器接口请求封装, 详情参考宜搭文档 https://docs.aliwork.com/docs/developer/api/openAPI

Methods

(async, static) deleteFormData(context, instanceId)

Description:
  • 删除表单实例数据
Source:
Example
// 使用前请添加数据源:
// 名称:deleteFormData
// 请求方法:POST
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/deleteFormData.json

deleteFormData(this, "FINST-12839128319823").then(() => {
  console.log("删除成功");
}, (e) => {
  console.log(`删除失败:${e.message}`);
});
Parameters:
Name Type Description
context Object this上下文
instanceId string 实例ID

(async, static) executeTask(context, instanceId, taskId, result, remark, formDataopt, noExecuteExpressionsopt) → {Promise}

Description:
  • 执行流程单个任务/流程节点审批
Source:
Example
// 使用前请添加数据源:
// 名称:executeTask
// 请求方法:POST
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/task/executeTask.json

executeTask(this, "FINST-xxxxxx", "25748312227", "AGREE", "同意", {}, 'n')
.then(() => {
    console.log("执行成功");
  },(e) => {
    console.log(`执行失败`);
  }
);
Parameters:
Name Type Attributes Description
context Object this上下文
instanceId string 实例ID
taskId string 任务ID,可通过 module:DataSource.getOperationRecords 方法获取流程当前及历史节点taskId
result "AGREE" | "DISAGREE" 审批结果
remark string 审批意见
formData Object <optional>
表单数据对象
noExecuteExpressions boolean <optional>
是否不执行校验&关联操作
Returns:
一个Promise
Type
Promise

(async, static) fetchSubformDatas(context, formUuid, formInstanceId, tableFieldId, currentPage, pageSize) → {Promise.<module:DataSource.SubformDatasResponse>}

Description:
  • 分页获取子表数据
Source:
Example
// 使用前请添加数据源:
// 名称:fetchSubformDatas
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/listTableDataByFormInstIdAndTableId.json

fetchSubformDatas(
  this,
  "FORM-xxxxxx",
  "FINST-xxxxxx",
  "tableField_xxxxxx",
   1, 50
 ).then(resp => {
   const { totalCount, subformDatas, currentPage } = resp;
 }, (e) => {
   console.log(`获取失败:${e.message}`);
 });
Parameters:
Name Type Description
context Object this上下文
formUuid string 表单ID
formInstanceId string 表单实例ID
tableFieldId string 子表唯一标识
currentPage number 当前页, 默认为1
pageSize number 每页记录数,最大50条,默认为10
Returns:
一个Promise,resolve响应对象,参见:module:DataSource.SubformDatasResponse
Type
Promise.<module:DataSource.SubformDatasResponse>

(async, static) fetchSubformDatasAll(context, formUuid, formInstanceId, tableFieldId) → {Promise.<Array.<Object>>}

Description:
  • 获取所有子表数据
Source:
Example
// 使用前请添加数据源:
// 名称:fetchSubformDatas
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/listTableDataByFormInstIdAndTableId.json

fetchSubformDatasAll(
  this,
  "FORM-xxxxxx",
  "FINST-xxxxxx",
  "tableField_xxxxxx",
 ).then(allsubformDatas => {
   console.log("子表数据:", allsubformDatas);
 }, (e) => {
   console.log(`获取失败:${e.message}`);
 });
Parameters:
Name Type Description
context Object this上下文
formUuid string 表单ID
formInstanceId string 表单实例ID
tableFieldId string 子表唯一标识
Returns:
一个Promise,resolve所有子表数据数组
Type
Promise.<Array.<Object>>

(static) getFormData(context, type, formInstId) → {Promise.<Object>}

Description:
  • 获取表单实例详情
Source:
Example
// 使用前请添加数据源:
// 如果要获取普通表单实例详情
// 名称:getFormData
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/getFormDataById.json
// 如果要获取流程表单实例详情
// 名称:getProcessInstance
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/getInstanceById.json

// 获取普通表单实例数据
getFormData(this, "form", "FINST-TD866Y81CHLF6FVA9WR6J7GQPBM72KUTJRFOL6T9")
.then(formData => {
  console.log("表单实例数据", formData);
}).catch(e => {
  console.log(`获取失败:${e.message}`);
});

// 获取流程表单实例数据
getFormData(this, "process", "62a1ef56-8ded-4e77-89a0-db32c95a6d04")
.then(formData => {
  console.log("流程实例数据", formData);
}).catch(e => {
  console.log(`获取失败:${e.message}`);
});
Parameters:
Name Type Description
context Object this上下文
type "form" | "process" 类型,取值为 form-表单 或者 porcess-流程
formInstId string 表单实例ID
Returns:
一个Promise,resolve表单实例数据
Type
Promise.<Object>

(async, static) getOperationRecords(context, instanceId) → {Promise.<module:DataSource~OperationRecord>}

Description:
  • 获取流程审批记录
Source:
Example
// 使用前请添加数据源:
// 名称:getOperationRecords
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/getOperationRecords.json

getOperationRecords(this, "2c517124-e73e-4528-acc8-28216c6c8df9")
.then((records) => {
    console.log("获取成功", records);
  },(e) => {
    console.log(`获取失败:${e.message}`);
  }
);
Parameters:
Name Type Description
context Object this上下文
instanceId string 流程实例ID
Returns:
一个Promise,resolve流程审批记录列表
Type
Promise.<module:DataSource~OperationRecord>

(async, static) invokeConnector(context, connectorName, params) → {Promise.<object>}

Description:
  • 调用连接器
Source:
Example
// 假设要通过连接器调用钉钉接口获取部门下的子部门信息
invokeConnector(this, "subDepts", {
  Query: {
    access_token: ""
  },
  Body: {
    dept_id: 1
  }
}).then((resp) => {
  console.log("请求成功: ", resp);
}, (e) => {
  console.log(`请求失败:${e.message}`);
})
Parameters:
Name Type Description
context object this上下文
connectorName string 连接器名称,数据源面板中添加连接器时配置的名称
params object 连接器执行动作参数
Returns:
Type
Promise.<object>

(async, static) saveFormData(context, formUuid, formData) → {Promise.<string>}

Description:
  • 新建表单实例
Source:
Example
// 使用前请添加数据源:
// 名称:saveFormData
// 请求方法:POST
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/saveFormData.json

saveFormData(
  this,
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello", numberField_xxxxxx: 100 },
).then(
  (instanceId) => {
    console.log("创建成功,实例ID:${instanceId}");
  },
  (e) => {
    console.log(`创建失败:${e.message}`);
  }
)
Parameters:
Name Type Description
context Object this上下文
formUuid string 表单ID
formData Object 表单数据对象
Returns:
一个Promise,resolve表单实例ID
Type
Promise.<string>

(async, static) searchFormDataIds(context, type, formUuid, searchFieldObject, currentPage, pageSize, options) → {Promise.<module:DataSource.FormDataIdsResponse>}

Description:
  • 查询表单实例ID列表
    ⚠️如果使用文本字段(单行/多行文本)作为查询条件,执行的是模糊查询,比如查询“张三”,会把“张三丰"也查询出来
Source:
Example
// 使用前请添加数据源:
// 如果要更新普通表单:
// 名称:searchFormDataIds
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/searchFormDataIds.json
// 如果要更新流程表单:
// 名称:getInstanceIds
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/getInstanceIds.json

// 搜索普通表单
searchFormDataIds(
  this,
  "form",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  1, 100,
  { dynamicOrder: { "numberField_xxx": "+" } }
).then((resp) => {
    const { currentPage, totalCount, ids } = resp;
    console.log(`共${totalCount}条数据`);
    console.log(ids);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);

// 搜索流程表单
searchFormDataIds(
  this,
  "process",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  1, 100,
  { dynamicOrder: { "numberField_xxx": "+" }, instanceStatus: "COMPLETED" }
).then((resp) => {
    const { currentPage, totalCount, ids } = resp;
    console.log(`共${e.totalCount}条数据`);
    console.log(ids);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);
Parameters:
Name Type Description
context Object this上下文
type "form" | "process" 表单类型,可选 form、process,分别代表普通表单和流程
formUuid string 表单ID
searchFieldObject Object 表单组件查询条件对象
currentPage number 当前页, 默认为1
pageSize number 每页记录数, 默认为10
options module:DataSource~SearchFormDatasOption 查询选项
Returns:
一个Promise,resolve表单实例ID响应对象 module:DataSource.FormDataIdsResponse
Type
Promise.<module:DataSource.FormDataIdsResponse>

(async, static) searchFormDataIdsAll(context, type, formUuid, searchFieldObject, options) → {Promise.<Array.<string>>}

Description:
  • 查询符合条件的所有表单实例ID
    ⚠️如果使用文本字段(单行/多行文本)作为查询条件,执行的是模糊查询,比如查询“张三”,会把“张三丰"也查询出来
Source:
Example
// 使用前请添加数据源:
// 如果要更新普通表单:
// 名称:searchFormDataIds
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/searchFormDataIds.json
// 如果要更新流程表单:
// 名称:getInstanceIds
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/getInstanceIds.json

// 搜索普通表单
searchFormDataIdsAll(
  this,
  "form",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  { dynamicOrder: "numberField_xxx": "+" }
).then((ids) => {
    console.log("查询成功", ids);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);

// 搜索流程表单
searchFormDataIdsAll(
  this,
  "process",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  { dynamicOrder: "numberField_xxx": "+", instanceStatus: "COMPLETED" }
).then((ids) => {
    console.log("查询成功", ids);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);
Parameters:
Name Type Description
context Object this上下文
type "form" | "process" 表单类型,可选 form、process,分别代表普通表单和流程
formUuid string 表单ID
searchFieldObject Object 表单组件查询条件对象
options module:DataSource~SearchFormDatasOption 查询选项
Returns:
一个Promise,resolve表单实例ID数组
Type
Promise.<Array.<string>>

(async, static) searchFormDatas(context, type, formUuid, searchFieldObject, currentPage, pageSize, options) → {Promise.<Array.<module:DataSource~FormDatasResponse>>}

Description:
  • 分页查询表单实例数据
    ⚠️如果使用文本字段(单行/多行文本)作为查询条件,执行的是模糊查询,比如查询“张三”,会把“张三丰"也查询出来。 若要精确查询,请将options参数的strictQuery选项设置为true
Source:
Example
// 使用前请添加数据源:
// 如果要更新普通表单:
// 名称:searchFormDatas
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/searchFormDatas.json
// 如果要更新流程表单:
// 名称:getInstances
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/getInstances.json

// 搜索普通表单
searchFormDatas(
  this,
  "form",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  1, 100,
  // 精确查询,按照numberField_xxx升序排序
  { strictQuery: true, dynamicOrder: "numberField_xxx": "+" }
).then((resp) => {
    const { currentPage, totalCount, formDatas } = resp;
    console.log(`共${totalCount}条数据`);
    console.log(formDatas);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);

// 搜索流程表单
searchFormDatas(
  this,
  "process",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  1, 100,
  // 精确查询,流程状态已完成,按照numberField_xxx升序排序
  { strictQuery: true, dynamicOrder: "numberField_xxx": "+", instanceStatus: "COMPLETED" }
).then((ids) => {
    const { currentPage, totalCount, formDatas } = resp;
    console.log(`共${totalCount}条数据`);
    console.log(formDatas);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);
Parameters:
Name Type Description
context Object this上下文
type "form" | "process" 表单类型,可选 form、process,分别代表普通表单和流程
formUuid string 表单ID
searchFieldObject Object 表单组件查询条件对象
currentPage number 当前页, 默认为1
pageSize number 每页记录数, 默认为10
options module:DataSource~SearchFormDatasOption 查询选项
Returns:
一个Promise,resolve表单实例ID响应对象 module:DataSource~FormDatasResponse
Type
Promise.<Array.<module:DataSource~FormDatasResponse>>

(async, static) searchFormDatasAll(context, type, formUuid, searchFieldObject, options) → {Promise.<Array.<Object>>}

Description:
  • 查询符合条件的所有表单实例
    ⚠️如果使用文本字段(单行/多行文本)作为查询条件,执行的是模糊查询,比如查询“张三”,会把“张三丰"也查询出来。 若要精确查询,请将options参数的strictQuery选项设置为true
Source:
Example
// 使用前请添加数据源:
// 如果要更新普通表单:
// 名称:searchFormDatas
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/searchFormDatas.json
// 如果要更新流程表单:
// 名称:getInstances
// 请求方法:GET
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/getInstances.json

// 搜索普通表单
searchFormDatasAll(
  this,
  "form",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  // 精确查询,按照numberField_xxx升序排序
  { strictQuery: true, dynamicOrder: { "numberField_xxx": "+" } }
).then((formDatas) => {
    console.log("查询成功", formDatas);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);

// 搜索流程表单
searchFormDatasAll(
  this,
  "process",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello" },
  // 精确查询,流程状态已完成,按照numberField_xxx升序排序
  { strictQuery: true, dynamicOrder: { "numberField_xxx": "+" }, instanceStatus: "COMPLETED" }
).then((formDatas) => {
    console.log("查询成功", formDatas);
  },(e) => {
    console.log(`查询失败:${e.message}`);
  }
);
Parameters:
Name Type Description
context Object this上下文
type "form" | "process" 表单类型,可选 form、process,分别代表普通表单和流程
formUuid string 表单ID
searchFieldObject Object 表单组件查询条件对象
options module:DataSource~SearchFormDatasOption 查询选项
Returns:
一个Promise,resolve表单实例数据数组
Type
Promise.<Array.<Object>>

(async, static) startInstance(context, processCode, formUuid, formData, dptIdopt) → {Promise.<string>}

Description:
  • 发起流程
Source:
Example
// 使用前请添加数据源:
// 名称:startInstance
// 请求方法:POST
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/startInstance.json

startInstance(
  this,
  "TPROC--xxxxxx",
  "FORM-xxxxxx",
  { textField_xxxxxx: "hello", numberField_xxxxxx: 100 },
).then(
  (instanceId) => {
    console.log("创建成功,实例ID:${instanceId}");
  },
  (e) => {
    console.log(`创建失败:${e.message}`);
  }
)
Parameters:
Name Type Attributes Description
context Object this上下文
processCode string 流程 code
formUuid string 表单ID
formData Object 表单数据对象
dptId string <optional>
发起部门ID,如不填默认为发起人主事部门
Returns:
一个Promise,resolve流程实例ID
Type
Promise.<string>

(async, static) updateFormData(context, type, instanceId, updateFormData, useLatestVersion) → {Promise}

Description:
  • 更新表单/流程实例数据
Source:
Example
// 使用前请添加数据源:
// 如果要更新普通表单:
// 名称:updateFormData
// 请求方法:POST
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/form/updateFormData.json
// 如果要更新流程表单:
// 名称:updateInstance
// 请求方法:POST
// 请求地址:/dingtalk/web/APP_xxxxxx/v1/process/updateInstance.json

updateFormData(
  this,
  "form",
  "FINST-xxxxxx",
  { textField_xxxxxx: "a new value" },
  true
).then(() => {
    console.log("更新成功");
  },(e) => {
    console.log(`更新失败:${e.message}`);
  }
);
Parameters:
Name Type Default Description
context Object this上下文
type "form" | "process" 表单类型,可选 form、process,分别代表普通表单和流程
instanceId string 实例ID
updateFormData Object 要更新的表单数据对象
useLatestVersion boolean false 是否使用最新的表单版本进行更新,默认为false,仅对普通表单有效
Returns:
一个Promise,更新成功时resolve,失败时reject
Type
Promise

Type Definitions

FormDataIdsResponse

Description:
  • 查询表单实例ID响应对象
Source:
Properties:
Name Type Description
totalCount number 表单数据总条数
currentPage number 当前页码
ids Array.<string> 表单实例ID数组
查询表单实例ID响应对象
Type:
  • Object

SubformDatasResponse

Description:
  • 获取子表数据响应对象
Source:
Properties:
Name Type Description
totalCount number 子表数据总条数
currentPage number 当前页码
subformDatas Array.<Object> 子表数据数组
获取子表数据响应对象
Type:
  • Object

ApprovedResult

Description:
  • 流程审批结果
    agree - 同意
    disagree - 不同意
Source:
流程审批结果
agree - 同意
disagree - 不同意
Type:
  • "agree" | "disagree"

FormData

Description:
  • 表单实例数据对象
Source:
Properties:
Name Type Description
title string 数据标题
formUuid string 表单formUuid
instanceId string 实例ID
processCode string 流程码(🚨仅流程包含该字段)
instanceStatus module:DataSource~ProcessStatus 流程状态(🚨仅流程包含该字段),可能值为:RUNNING, TERMINATED, COMPLETED, ERROR。分别代表:运行中,已终止,已完成,异常。
approvedResult module:DataSource~ApprovedResult 审批结果(🚨仅流程包含该字段)
creator string 创建人ID(🚨仅表单包含该字段)
originator Object 发起人对象
originatorCorpId string 发起人企业ID
originatorCorpName string 发起人企业名称
gmtCreate number 创建时间戳
modifier string 最后修改人ID(🚨仅表单包含该字段)
modifyUser Object 最后修改人对象(🚨仅表单包含该字段)
gmtModified number 最后修改时间戳
表单实例数据对象
Type:
  • Object.<string, *>

FormDatasResponse

Description:
  • 查询表单实例数据响应对象
Source:
Properties:
Name Type Description
totalCount number 表单数据总条数
currentPage number 当前页码
actualPageSize number 接口返回的当前页数据量,当开启严格查询时, 由于进行了额外的筛选,方法返回的数据量量可能小于接口返回的数据量
formDatas Array.<module:DataSource~FormData> 表单实例数据数组
查询表单实例数据响应对象
Type:
  • Object

OperationRecord

Description:
  • 流程审批记录对象
Source:
Properties:
Name Type Description
action string 动作描述文本,仅已处理节点有该字段
actionExt "submit" | "agree" | "disagree" | "doing" | "next" 动作描述码, submit表示提交节点、agree表示节点审批结果为同意、disagree表示审批结果为不同意、 doing表示当前节点,next表示此节点为后续待审批节点
activityId string 活动ID
domains Array
operator string 操作人ID
operatorAgentIds Array.<string> 代理人ID
operatorDisplayName string 操作人显示名
operatorName string 操作人姓名
operatorPhotoUrl string 操作人头像链接
processInstanceId string 流程实例ID
showName string 节点名
size number -
taskHoldTime number 任务持续时间?
taskId string 任务ID
type "HISTORY" | "TODO" 记录类型,HISTORY表示已处理的节点,TODO表示待处理节点
流程审批记录对象
Type:
  • Object

ProcessStatus

Description:
  • 流程实例状态
    RUNNING - 运行中
    TERMINATED - 已终止
    COMPLETED - 已完成
    ERROR - 异常
Source:
流程实例状态
RUNNING - 运行中
TERMINATED - 已终止
COMPLETED - 已完成
ERROR - 异常
Type:
  • "RUNNING" | "TERMINATED" | "COMPLETED" | "ERROR"

SearchFormDatasOption

Description:
  • 搜索表单(流程)实例数据(ID)选项
Source:
Properties:
Name Type Description
strictQuery boolean 严格(精确)查询,默认不启用。当使用单行文本或者多行文本组件作为查询条件时执行的是模糊查询, 比如查询"张三"会把“张三丰”也查询出来。将strictQuery设置为ture会对查询结果执行进一步筛选,保证返回文本严格相等的数据。
⚠️查询表单实例ID方法module:DataSource.searchFormDataIds module:DataSource.searchFormDataIdsAll不支持此选项。
⚠️如果使用分页查询,严格查询的结果数量可能少于分页数量。
dynamicOrder Object 排序规则
originatorId string 数据提交人/流程发起人工号
createFrom string 查询在该时间段创建的数据列表
createTo string 查询在该时间段创建的数据列表
modifiedFrom string 查询在该时间段有修改的数据列表
modifiedTo string 查询在该时间段有修改的数据列表
taskId string 任务ID,仅查询流程表单有效
instanceStatus module:DataSource~ProcessStatus 实例状态,仅查询流程表单有效,可选值为:RUNNING, TERMINATED, COMPLETED, ERROR。分别代表:运行中,已终止,已完成,异常。
approvedResult module:DataSource~ApprovedResult 流程审批结果,仅查询流程表单有效,可选值为agree、disagree,分别代表同意、不同意。
搜索表单(流程)实例数据(ID)选项
Type:
  • Object