> For the complete documentation index, see [llms.txt](https://docs.coreway.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coreway.com/coreway-table/automation/flow-control/sub-workflow.md).

# 子流程

### 1. 節點功能

當某個業務流程是通用流程、可以被重複使用時，則可以配置為子流程，供其他流程調用，極大地減少了流程的重複配置。

子流程可作為單獨的工作流程看待；當子流程執行完後，數據將會回到主流程。但子流程不能單獨創建，需要在主流程中才能創建並使用。

### 2. 場景示例

例如，在退貨售後場景中，一個訂單發起退貨後需要進行派單取貨，再進行退貨入庫；當商品完成入庫後才執行財務退款。那麼我們可以將「退貨派單到入庫」這部分業務拆分到子流程去處理。

當子流程完成入庫操作以後，再回到主流程裡，進行財務退款審批，完成最終的退貨退款流程。

流程設計：

* **主流程**：發起退貨（新增退貨單）→ 退貨審批（審批通過時）→ 子流程入庫 →（已入庫）→ 財務退款

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2Fl2rNXJVUDYEmoKLkwRfI%2F19753871560345.png?alt=media)

* **子流程**：發起派單（填寫取件人）→ 取件人取件（錄入取件情況）→ 倉庫入庫（錄入是否入庫）

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2FBrPd0bmYYUV51mswJxwa%2F19755202816281.png?alt=media)

### 3. 子流程節點設置

#### 3.1 選擇數據對象

在主流程裡添加一個子流程節點，選擇數據對象。數據對象指的是選擇將哪個節點的數據傳給子流程，選擇的節點對象將作為子流程的數據源。

注意：數據源有可能是單條數據，也可能是多條數據，這可以決定子流程的執行方式。

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2FJujrzXAgTe6AiiPBssj9%2F19753871564953.png?alt=media)

#### 3.2 配置子流程

如果沒有可選擇的子流程，直接點擊保存；保存後，可以直接從主流程中進入到子流程配置頁面。

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2FDwnk6KvNsi9aWSnISg5m%2F19753989496601.png?alt=media)

如下圖所示，點擊子流程節點的箭頭處。

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2FVJ5cVywGyMTQBJRboUEq%2F19755106380057.png?alt=media)

進入為命名子流程頁面，配置方式和流程配置一樣，配置好後點擊發布即可。

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2FYLVYwow6lZ99uBihB2xR%2F19754927334553.png?alt=media)

回到主流程配置子流程節點，即可選擇剛剛發布的子流程。

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2FzMqOEtAhzuZAlA2GfOJd%2Ffc8c860921719968f1063d2ca2f5cb24.png?alt=media)

#### 3.3 參數傳遞

你還可以設置參數，向子流程的流程參數傳遞初始值，供子流程執行時使用。

![image.png](https://273888574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9WI4IMScYYFwRQSZY8Zr%2Fuploads%2FjkOcPJYxUw6F0jwSPCry%2F6128eecad829d5ec3c8ca3c99e60919e.png?alt=media)

* A：可以直接在子流程中設置參數，流程參數請參考「更新流程參數」。
* B：將參數添加為子流程參數字段。

設置好後，我們就可以在子流程配置中將這些字段作為條件參數等使用。

#### 3.4 選擇執行方式

如果是多條數據（數據對象選擇的是獲取批量數據節點），那麼子流程有兩種執行順序的設定：

* **並行**：如果這些記錄是各自處理各自的內容，則並行即可。即便某條子流程運行中止，也不影響其他子流程的執行。
* **逐條執行**：每條子流程需要等前一條子流程通過後再開始觸發；如果某條子流程運行終止，則後續的子流程都不再執行。

#### 3.5 子流程執行完畢後，再開始執行下一個節點

* 如果勾選，那麼會等待子流程執行完畢後，才會執行後面的節點；另外，勾選後，當子流程數據源為單條對象，之後節點可使用子流程中的參數。
* 如果不勾選，那麼子流程和後續的節點同時進行，子流程的執行結果對當前流程沒有任何影響。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.coreway.com/coreway-table/automation/flow-control/sub-workflow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
