Sequential Command
Run a series of commands in order, waiting for the previous command to finish before starting the next. The Sequential
command finishes after all its child commands have finished.
Properties
The Sequential
command has the properties shown in the following table, in addition to the common command properties. Set the type
property to Sequential
.
In the following table, the "Default" column shows "Required" for properties that must have a value for the command to run. Otherwise it displays the default value, which might be none.
Property | Type | Default | Description |
---|---|---|---|
|
Array of Commands |
[] |
An ordered list of commands to run if this sequence stops early. |
|
Array of Commands |
Required |
An ordered list of command to run in series. |
|
Array |
[] |
A list of data to map against the commands. |
|
Integer |
0 |
Additional number of times to run these commands. |
|
Array of Commands |
[] |
An ordered list of commands to run after the normal commands and the catch commands. |
In normal mode the commands
run in order, followed by the finally
commands. The repeatCount
only applies to the regular commands.
In fast mode the commands
run in order without repeating, followed by the finally
commands.
If one of the commands
stops early (in normal mode), the catch
commands and finally
commands run in fast mode.
If one of the finally
commands stops while running in normal mode, the remaining finally
commands run in fast mode.
catch
catch
requires APL 1.1 or later. Provide an alternate experience for devices running older versions of APL.
The catch commands run if the Sequential
command stops due to another command running. The catch commands run in "fast" mode – that is, all durations are ignored and commands jump to their final values. The catch commands run before any finally
commands.
The catch
commands run one time. The repeatCount
property doesn't apply to catch
commands.
commands
An array of commands to run. The commands run in array order, and each command must finish before the next one can begin. The delay
value of the Sequential
command and the delay
value of the first command in the sequence are additive. In the following example, the first SendEvent
command runs after 3000 milliseconds.
{
"type": "Sequential",
"delay": 1000,
"repeatCount": 2,
"commands": [
{
"type": "SendEvent",
"delay": 2000
},
{
"type": "SendEvent",
"delay": 2000
}
]
}
data
The array of data to iterate over. When the data
array contains data, the Sequential
command iterates that array and creates a new Sequential
command for each value in the array. Each new Sequential
command contains the commands from the original commands
property. This is similar to the way data array inflation works for multiple-child components.
For example, the following Sequential
command contains two commands in commands
and two strings in the data
array.
{
"type": "Sequential",
"data": ["item1", "item2"],
"commands": [
{
"type": "CustomCommand1",
"item": "${data}"
},
{
"type": "CustomCommand2",
"item": "${data}"
}
],
"catch": {
"type": "OnFailCustom"
},
"finally": {
"type": "OnFinishedCustom"
}
}
This command expands into a Sequential
command that contains one Sequential
for each of the two items in data
. The final command to run is therefore the following.
{
"type": "Sequential",
"commands": [
{
"type": "Sequential",
"commands": [
{
"type": "CustomCommand1",
"item": "item1"
},
{
"type": "CustomCommand2",
"item": "item1"
}
]
},
{
"type": "Sequential",
"commands": [
{
"type": "CustomCommand1",
"item": "item2"
},
{
"type": "CustomCommand2",
"item": "item2"
}
]
}
],
"catch": {
"type": "OnFailCustom"
},
"finally": {
"type": "OnFinishedCustom"
}
}
During iteration, the data-binding context extends to include the properties shown in the following table.
Name | Description |
---|---|
|
Data assigned from the data array property. |
|
The 0-based index of the current data item. |
|
The total number of data items in the data array. |
These properties are set when the data
array property contains at least one item.
The data
array property doesn't affect the behavior of the catch
and finally
properties.
finally
finally
requires APL 1.1 or later. Provide an alternate experience for devices running older versions of APL.
The finally
commands run after the normal sequential commands finish or after the catch
commands run due to the command stopping early. The finally
commands run in normal mode unless (a) the entire Sequential command ran in fast mode or (b) the sequential command stopped early.
The finally
commands run one time. The repeatCount
property doesn't apply to finally
commands.
repeatCount
The number of times to repeat this series of commands. Defaults to 0. Negative values will be ignored.
Reinflation strategy
When the Reinflate
command runs, the Sequential
command can resume after Alexa reinflates the document. The command resumes when it runs on a sequencer
that is specified in the preservedSequencers
array on Reinflate
. The command saves the current repeat number, repeat count, and list of commands.
When Alexa reinflates the document, the currently running command continues to run as specified by its reinflation strategy.
Sequential example with the data array
The following example displays a list of items. The button defines a Sequential
with three SetValue
commands to select a random color from a list, change the color of an item to the random color, and then change the text of the item to the name of the color. The Sequential
sets the data
array to the same list of items displayed in the Sequence
.
When the command runs, each item in the list first changes color, then changes its text. The items update one after another.
For a similar example in which the list items update at the same time, see Parallel example with the data array.
Related topics
Last updated: frontmatter-missing