> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # execute > Call a named section as a subroutine and return when it completes. Call a named section as a subroutine. Execution continues in the called section, then returns to the caller when the section completes (via [`return`](/docs/swml/reference/messaging/return) or by reaching the end of the section). The destination must be the **name of a section** defined in the current document — `execute` does not accept URLs or inline documents in the messaging context. ## **Properties** **`execute`** `object` — required An object that accepts the following properties. --- **`execute.dest`** `string` — required Name of the section to execute. Must reference a section defined in the current document. --- **`execute.params`** `object` Parameters accessible as `params.*` in the called section. Replaces (does not merge with) any outer `params` from the caller. --- ## **Variables** After the called section completes, `execute` exposes the following variable in the caller's context. Variables that the subroutine itself set via [`reply`](/docs/swml/reference/messaging/reply) or [`request`](/docs/swml/reference/messaging/request) — `reply_result`, `reply_message_id`, `request_result`, `request_response`, `request_response_code`, `request_response_body` — are also propagated back to the caller automatically; see those methods for details. **`return_value`** `any` The value supplied to [`return`](/docs/swml/reference/messaging/return) inside the called section. Set only when the subroutine called `return` with an argument. Absent when the subroutine ran to completion without `return`. --- ## **Examples** ### Calling a subroutine #### YAML ```yaml version: 1.0.0 sections: main: - execute: dest: greet params: name: "%{message.from}" - reply: body: "%{return_value}" greet: - return: "Hello, %{params.name}!" ``` #### JSON ```json { "version": "1.0.0", "sections": { "main": [ { "execute": { "dest": "greet", "params": { "name": "%{message.from}" } } }, { "reply": { "body": "%{return_value}" } } ], "greet": [ { "return": "Hello, %{params.name}!" } ] } } ``` ### Branch on the subroutine return value #### YAML ```yaml version: 1.0.0 sections: main: - execute: dest: classify params: body: "%{message.body}" - switch: variable: return_value case: opt_out: - reply: body: "You've been unsubscribed." help: - reply: body: "Reply STOP to unsubscribe." default: - reply: body: "Thanks for your message!" classify: - switch: variable: params.body transform: lowercase_trim case: stop: - return: "opt_out" help: - return: "help" default: - return: "other" ``` #### JSON ```json { "version": "1.0.0", "sections": { "main": [ { "execute": { "dest": "classify", "params": { "body": "%{message.body}" } } }, { "switch": { "variable": "return_value", "case": { "opt_out": [ { "reply": { "body": "You've been unsubscribed." } } ], "help": [ { "reply": { "body": "Reply STOP to unsubscribe." } } ] }, "default": [ { "reply": { "body": "Thanks for your message!" } } ] } } ], "classify": [ { "switch": { "variable": "params.body", "transform": "lowercase_trim", "case": { "stop": [ { "return": "opt_out" } ], "help": [ { "return": "help" } ] }, "default": [ { "return": "other" } ] } } ] } } ``` > Call a named section as a subroutine and return when it completes.