RUNSUB

此説明頁面適用於 Studio。 此資訊亦適用於 Desktop Studio。

``` Icon of Runsub: purple circles linked by arrows ```

呼叫子程式碼,該子程式碼會執行,然後使用Return 動作返回並繼續執行主要程式碼。 當子程式碼執行時,它會將值儲存在 Return 動作的 ReturnValue 屬性中,然後將該值傳回主要程式碼中 Runsub 動作的 ReturnVariable 屬性。

若您有一個或多個較大的指令碼,而您希望將其分解為較小的指令碼,則此動作尤其有用。

相依性

  • 子程式碼必須與主要程式碼位於同一資料夾,或位於其子資料夾中。

  • 主指令碼類型和子指令碼類型必須相同。例如,如果主指令碼為電話指令碼,則子指令碼也必須為電話指令碼。
  • 若在主要指令碼中放置一個 Runsub 動作,則子指令碼必須有一個 Return 動作。
  • Runsub 可將多個變數從主要指令碼傳遞給子指令碼,但子指令碼只能向主要指令碼返回一個值(在 ReturnVariable 屬性中)。
  • 當子指令碼終止時,在您將子指令碼聲明為全域之前,子指令碼中定義的任何變數將不再可用。 您可以在SNIPPET動作中,在變數名稱前加上global:來執行此操作。 例如:ASSIGN global:varName = value。 另一個存取子指標中數據的選項是使用 GET /contacts/{contactId}/custom-data An icon of a square with an arrow  pointing from the center out to the upper right corner. API。
  • 若要在Runsub子腳本中對某變數使用savetodb()函數,該變數必須為全域變數。
  • 所有由 RunScript、Spawn、Runsub 或類似指令碼呼叫的指令碼都必須有效並處於啟用狀態。 在儲存過程中,Studio會驗證所有由動作調用的指令碼。 如果其中任何一個無效或非活躍,Studio將顯示一個錯誤並無法儲存。

支援的程式碼類型

一個正方形,其上有一條通往其他三個正方形的分支線。

Icon of gray-green envelope

深綠色語音氣泡圖示

Icon of purple telephone handset

鏽色留言符號圖示,由兩個以線條相連的圓形組成

Icon of pink document with lines of text

Icon of green mobile phone with a speech bubble on its screen

Icon of purple computer monitor with a mobile device overlapping its lower right corner

通用

電郵 聊天 電話 語音郵件 工作項目 SMS Digital

類似動作比較

以下動作有類似的功能,但有一些金鑰差異:

  • Runscript:當 Runscript 觸發另一個程式碼時,它不會從第二個程式碼返回第一個程式碼。
  • Runsub:當 Runsub 觸發子程式碼時,只要子程式碼具有 Return 動作,該程式碼便可返回第一個程式碼。該子指令碼完成後,Return 將向 Runsub 動作傳回一個值。
  • SPAWN:啟動與第一個指令碼並行執行的第二個指令碼。除非您在衍生的指令碼中加入SIGNAL動作,否則衍生的指令碼無法將資料傳回第一個指令碼。

輸入屬性

這些屬性定義了動作執行時使用的資料。

屬性

描述

新增標題

Enter a short phrase that uniquely identifies this action in the script. The caption appears on the script canvas under the action icon.

指令碼名稱

您想要建置的指令碼。 您可以按一下動作屬性方塊頂部的連結,以從您的業務單元中選取程式碼。從下拉式清單中選擇一個程式碼,或輸入其名稱及相對路徑。 程式碼必須與呼叫程式碼位於同一資料夾,或位於其子資料夾之一。

返回變數

The value that is returned to the main script is stored in this property. To pass multiple values, use an array as the variable.
參數

Allows you to change the name of the default variables that hold values for parameters you want to send to the spawned or child script. The default variables are p1 - p9, but if you specify names in this property, those names replace the default variable names that the parameter values are passed in. If you don't change the names, the variables retain their default pX names.

要變更名稱,請按一下該欄位中的省略號圖示,並為您要傳送至衍生或子程式碼的每個參數新增變數名稱。在編輯視窗中輸入最多九個名稱,每行一個。 要變更名稱,請為您要傳送至衍生或子程式碼的每個參數新增新的名稱。輸入最多九個變數名稱,每行一個。 變數名稱不必與衍生程式碼中使用的對應變數名稱相符,但應具有意義。這些值會以參數變數參數變數 p1 - p9 的形式傳遞。

傳入指令碼的參數會顯示在該指令碼的追蹤輸出中的Begin動作裡。

結果分支條件

結果分支條件允許您在指令碼中建立分支,以處理執行動作時的不同結果。

條件

描述

預設

Path taken unless the script meets a condition that requires it to take one of the other branches. It is also taken if the action's other branches are not defined.

Error

Path taken when the action fails to execute properly. For example, when there is an unexpected problem such as poor connectivity, syntax errors, and so on. The _ERR variable, with a single underscore character, should be populated with a condensed explanation of the problem.

程式碼範例

下面是一個範例,說明如何在指令碼中使用此動作。 這不是一個完整的指令碼。 可能需要額外的指令碼。

在下面的主要指令碼(頂部所示)中,當指令碼被觸發時,Runsub 動作會立即觸發子指令碼(底部所示)。 在下標中,Voiceparams設定文字轉語音設定,而Hours動作則為營業、停業及假期設定三個不同Return動作的分支。 當子程式碼完成後,ReturnValues 屬性(位於Return 動作中)的值會儲存在 ReturnVariable 欄位中(位於主要程式碼的 Runsub 動作中)。 然後,Case 動作根據需要設定營業、不營業和假期分支。

主要程式碼

Main script using the RUNSUB action

下載此程式碼。

子指令碼

``` Subscript with three Return actions that set the ReturnValue used by the Case action in the main script ```

三個Return動作會在ReturnValue屬性中提供值,以便主要程式碼中的Case動作可以判斷要關注哪個分支。

下載此程式碼。