异步检索为当前用户可以切换到的表启用的业务流程。
Syntax
formContext.data.process.getEnabledProcesses(callbackFunction(enabledProcesses));
参数
| Name | 类型 | 必选 | Description |
|---|---|---|---|
callbackFunction |
功能 | 是的 | 回调函数必须接受一个参数,该参数包含包含字典属性的对象,其中属性的名称是业务流程的 ID,而该属性的值是业务流程的名称。 启用的进程根据用户的权限进行筛选。 启用的进程列表与用户希望在 UI 中手动更改该过程时可以看到的相同。 |
Example
示例中的 Sdk.formOnLoad 函数使用 formContext.data.process.getEnabledProcesses 方法异步检索为表启用的业务流程的信息。 该示例将匿名函数作为第一个参数传递。 返回数据并将数据作为参数传递给匿名函数时,以异步方式执行此函数。
有关启用的业务流程的信息作为字典对象提供,其中进程的 ID 是属性的名称,业务流程的名称是该属性的值。 示例代码处理此信息,并将全局 Sdk.enabledProcesses 数组中的值设置为稍后执行的逻辑进行访问。 该示例还循环访问 Sdk.enabledProcesses 数组中的值,并使用 Sdk.writeToConsole 函数将检索到的业务流程的信息写入控制台。
注释
示例 JavaScript 库中的 Sdk.formOnLoad 函数必须设置为窗体的 OnLoad 事件处理程序,并且必须在“处理程序属性”对话框中选中“传递执行上下文”作为第一个参数复选框。
此外,此示例只说明了 在 formContext.data.process API 中使用某些方法。 它不表示使用此 API 来满足业务要求;它仅用于演示如何在代码中访问键属性值。
//A namespace defined for SDK sample code
//You should define a unique namespace for your libraries
var Sdk = window.Sdk || {};
(function () {
//A global variable to store information about enabled business processes after they are retrieved asynchronously
this.enabledProcesses = [];
// A function to log messages while debugging only
this.writeToConsole = function (message) {
if (typeof console != 'undefined')
{ console.log(message); }
};
// Code to run in the OnLoad event
this.formOnLoad = function (executionContext) {
// Retrieve the formContext
var formContext = executionContext.getFormContext();
// Retrieve Enabled processes
formContext.data.process.getEnabledProcesses(function (processes) {
//Move processes to the global Sdk.enabledProcesses array;
for (var processId in processes) {
Sdk.enabledProcesses.push({ id: processId, name: processes[processId] })
}
Sdk.writeToConsole("Enabled business processes flows retrieved and added to Sdk.enabledProcesses array.");
//Write the values of the Sdk.enabledProcesses array to the console
if (Sdk.enabledProcesses.length < 0) {
Sdk.writeToConsole("There are no enabled business process flows for this table.");
}
else {
Sdk.writeToConsole("These are the enabled business process flows for this table:");
for (var i = 0; i < Sdk.enabledProcesses.length; i++) {
var enabledProcess = Sdk.enabledProcesses[i];
Sdk.writeToConsole("id: " + enabledProcess.id + " name: " + enabledProcess.name)
}
}
//Any code that depends on the Sdk.enabledProcesses array needs to be initiated here
});
};
}).call(Sdk);
在打开浏览器开发人员工具的情况下运行此示例时,下面是为启用了多个业务流程的表写入控制台的输出示例。
Enabled business processes flows retrieved and added to Sdk.enabledProcesses array.
These are the enabled business process flows for this table:
id: 7994be68-899e-4a40-8d18-f5c3b6940188 name: Sample Lead Process
id: 919e14d1-6489-4852-abd0-a63a6ecaac5d name: Lead to Opportunity Sales Process