Skip to navigation
Calling

return

View as MarkdownOpen in Claude

Return from execute or exit script.

return
anyRequired

The return value: a string, number, object, or array. Booleans and null can appear inside an object or array, or result from resolving a variable reference, but aren’t accepted directly as the whole return value.

Properties

No specific parameters.

SWML variables and expressions are resolved before the value is stored: in a string value, and in every string inside an object or array. Object keys aren’t resolved. A string that is a single variable reference, such as '${call.from}', keeps that variable’s JSON type; a reference combined with other text produces a string.

After resolution, the value can nest objects and arrays at most 62 levels deep. A deeper value isn’t stored, return_value keeps its previous value if it had one, and the section still ends. Because execute clears return_value before running its destination, an earlier result isn’t returned in that case.

Variables

Set by the method:

  • return_value:(out) Optional return value.

Examples

Return with optional value

version: 1.0.0
sections:
main:
- return: 1

Return with multiple values

version: 1.0.0
sections:
main:
- execute:
dest: fn_that_returns
- play:
url: 'say: returned ${return_value[0].a}'
fn_that_returns:
- return:
- a: 1
- b: 2

Return an object built from variables

version: 1.0.0
sections:
main:
- execute:
dest: collect_details
on_return:
- play:
url: 'say: ${return_value.caller} asked for ${return_value.department}'
collect_details:
- set:
department: sales
- return:
caller: '${call.from}'
department: '${department}'

using the on_return parameter

version: 1.0.0
sections:
main:
- execute:
dest: fn_that_returns
on_return:
- play:
url: 'say: returned ${return_value}'
fn_that_returns:
- return: hello

Return with no value

version: 1.0.0
sections:
main:
- return: {}

Additional examples are available in the introduction.