以非同步方式擷取為目前使用者可以切換至的資料表啟用的商務程序流程。
語法
formContext.data.process.getEnabledProcesses(callbackFunction(enabledProcesses));
參數
| 名稱 | 類型 | 為必填項目 | Description |
|---|---|---|---|
callbackFunction |
功能 | Yes | 回呼函式必須接受參數,其中包含具有字典屬性的物件,其中屬性的名稱是商務程序流程的識別碼,而屬性的值是商務程序流程的名稱。 已啟用的進程會根據使用者的權限進行篩選。 已啟用的處理程序清單與使用者想要手動變更處理程序時可以在 UI 中看到的處理程序清單相同。 |
Example
範例中的 Sdk.formOnLoad 函式會使用 formContext.data.process.getEnabledProcesses 方法,以非同步方式擷取已啟用資料表之商務程序流程的相關資訊。 範例會傳遞匿名函式作為第一個參數。 當傳回資料並將資料作為參數傳遞給匿名函數時,此函數會以非同步方式執行。
已啟用商務程序流程的相關資訊會以字典物件的形式提供,其中程式的識別碼是屬性的名稱,而商務程式流程的名稱是屬性的值。 範例程式碼會處理此資訊,並將全域 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