取得目前作用中路徑中的階段集合,以及與商務程序流程控制項中顯示的階段互動的方法。
作用中路徑代表目前根據記錄中的分支規則和目前資料在流程控制中呈現的階段。
語法
var stageCollection = formContext.data.process.getActivePath();
傳回值
類型:集合。
描述:根據分支規則中滿足的條件,所有已完成階段、目前作用中的階段,以及預測的未來階段集的集合。 這可能是 formContext.data.process 傳回的階段子集。getActiveProcess ,因為它只會包含那些階段,這些階段代表根據處理程序中發生的分支,從目前階段有效轉換。
Example
Sdk.formOnLoad 函式會使用 formContext.data.process.getActivePath 方法來擷取階段集合。 然後,範例程式碼會使用集合的 forEach 方法來迴圈每個階段。 然後,程式碼會使用此程式庫中定義的 Sdk.writeToConsole 函式,將階段的索引鍵屬性寫入主控台。 然後,程式碼會使用 getSteps 方法存取每個階段的步驟集合。 最後,範例會使用步驟集合的 forEach 方法來存取每個步驟,並將步驟的索引鍵屬性寫入主控台。
備註
範例 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 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();
// Enumerate the stages and steps in the active path
var activePathCollection = formContext.data.process.getActivePath();
activePathCollection.forEach(function (stage, n) {
Sdk.writeToConsole("Stage Index: " + n);
Sdk.writeToConsole("Table: " + stage.getEntityName());
Sdk.writeToConsole("StageId: " + stage.getId());
Sdk.writeToConsole("Status: " + stage.getStatus());
var stageSteps = stage.getSteps();
stageSteps.forEach(function (step, i) {
Sdk.writeToConsole(" Step Name: " + step.getName());
Sdk.writeToConsole(" Step Column: " + step.getAttribute());
Sdk.writeToConsole(" Step Required: " + step.isRequired());
Sdk.writeToConsole(" ---------------------------------------")
})
Sdk.writeToConsole("---------------------------------------")
});
};
}).call(Sdk);
當範例在瀏覽器中執行時,您可以使用瀏覽器的開發人員工具來檢視寫入主控台的文字。 例如,當此範例在 [機會] 表單中與 [機會銷售流程] 一起執行時,會將下列內容寫入主控台:
Stage Index: 0
Table: opportunity
StageId: 6b9ce798-221a-4260-90b2-2a95ed51a5bc
Status: active
Step Name: Identify Contact
Step Column: parentcontactid
Step Required: false
---------------------------------------
Step Name: Identify Account
Step Column: parentaccountid
Step Required: false
---------------------------------------
Step Name: Purchase Timeframe
Step Column: purchasetimeframe
Step Required: false
---------------------------------------
Step Name: Estimated Budget
Step Column: budgetamount
Step Required: false
---------------------------------------
Step Name: Purchase Process
Step Column: purchaseprocess
Step Required: false
---------------------------------------
Step Name: Identify Decision Maker
Step Column: decisionmaker
Step Required: false
---------------------------------------
Step Name: Capture Summary
Step Column: description
Step Required: false
---------------------------------------
---------------------------------------
Stage Index: 1
Table: opportunity
StageId: 650e06b4-789b-46c1-822b-0da76bedb1ed
Status: inactive
Step Name: Customer Need
Step Column: customerneed
Step Required: false
---------------------------------------
Step Name: Proposed Solution
Step Column: proposedsolution
Step Required: false
---------------------------------------
Step Name: Identify Stakeholders
Step Column: identifycustomercontacts
Step Required: false
---------------------------------------
Step Name: Identify Competitors
Step Column: identifycompetitors
Step Required: false
---------------------------------------
---------------------------------------
Stage Index: 2
Table: opportunity
StageId: d3ca8878-8d7b-47b9-852d-fcd838790cfd
Status: inactive
Step Name: Identify Sales Team
Step Column: identifypursuitteam
Step Required: false
---------------------------------------
Step Name: Develop Proposal
Step Column: developproposal
Step Required: false
---------------------------------------
Step Name: Complete Internal Review
Step Column: completeinternalreview
Step Required: false
---------------------------------------
Step Name: Present Proposal
Step Column: presentproposal
Step Required: false
---------------------------------------
---------------------------------------
Stage Index: 3
Table: opportunity
StageId: bb7e830a-61bd-441b-b1fd-6bb104ffa027
Status: inactive
Step Name: Complete Final Proposal
Step Column: completefinalproposal
Step Required: false
---------------------------------------
Step Name: Present Final Proposal
Step Column: presentfinalproposal
Step Required: false
---------------------------------------
Step Name: Confirm Decision Date
Step Column: finaldecisiondate
Step Required: false
---------------------------------------
Step Name: Send Thank You
Step Column: sendthankyounote
Step Required: false
---------------------------------------
Step Name: File De-brief
Step Column: filedebrief
Step Required: false
---------------------------------------
---------------------------------------