Server Connect Actions: Control Flow & Reuse
Learn the power tools in the editor: conditionals, switch/select, try/catch, loops, parallel, and reusable library actions.
Control flow + reuse
Section titled “Control flow + reuse”This tour shows the control-flow tools that make larger server actions readable and reusable: If, Select/Switch, Try/Catch, loops, parallel patterns, and library actions.
Opening the sample action…
Section titled “Opening the sample action…”Loading the example action into the Server Connect editor.
If this is the first time, it can take a moment while the editor initializes.
Orient yourself in Server Connect editor
Section titled “Orient yourself in Server Connect editor”Start with the wider context in the Server Connect editor so the next control makes sense in the full workflow. In the next step, you will focus on Containers create nested flows and see how it fits into this area.
Containers create nested flows
Section titled “Containers create nested flows”In the Steps tree, some actions are containers: they own nested steps.
Typical containers: If/Then/Else, Switch/Select, Try/Catch, Repeat/While, Group/Parallel.
This tour opens a sample action so you can see these patterns in a real workflow.
Conditionals: If / Then / Else
Section titled “Conditionals: If / Then / Else”If / Then / Else is your go-to for branching logic.
Common uses include validating inputs, handling missing records, enforcing permissions, and returning a friendly error shape early.
Tip: keep the condition readable—compute complex expressions in a separate step first.
If Properties: the condition + branches
Section titled “If Properties: the condition + branches”With the If container selected, focus on the Properties panel:
- If: the expression that decides the branch.
- Then and Else: the nested steps that run in each path.
Rule of thumb: compute complex expressions in a Set Value step first, then keep If readable.
Then/Else steps are normal steps
Section titled “Then/Else steps are normal steps”Inside Then/Else you add normal steps (often Set Value, Return, or Error).
Select the step and look at its Properties:
- Global Name (key) defines the variable name
- Value defines the computed value
- Output controls if it appears in the response
Multi-branch: Switch / Select
Section titled “Multi-branch: Switch / Select”When there are more than two choices, Switch/Select is often clearer than stacking many If blocks.
Use it when you need to handle a set of known cases (and optionally a default case).
Multi-branch container: expression + cases
Section titled “Multi-branch container: expression + cases”The Select container’s Properties describe:
- Expression: what you’re switching on (mode/type/status/etc)
- Cases: each case has a match value and nested steps
- Optional Default / fallback case
This pattern is often clearer than stacking many If blocks.
Case steps: return consistent output
Section titled “Case steps: return consistent output”Each case should produce a consistent output shape.
In this sample, the selected Select container shows the case definitions in Properties, including the values that set mode_message for the response.
Try/Catch: handle expected failures
Section titled “Try/Catch: handle expected failures”Use Try / Catch when a step can fail and you want a controlled result.
Common patterns: return a structured error response, map a low-level error into a user-friendly message, or add fallback logic.
Tip: only catch what you can handle—don’t hide unexpected errors.
IMPORTANT: Use try/catch for expected failures. For logic errors (wrong bindings, missing fields), fix the flow and schema instead.
Try/Catch Properties: map failures to responses
Section titled “Try/Catch Properties: map failures to responses”Try/Catch is a container with two nested parts:
- Try: steps that might throw/fail
- Catch: steps that handle the error
In Catch you usually build a predictable JSON response (status + message + details) instead of letting the request crash.
Core action: Error (and Catch variables)
Section titled “Core action: Error (and Catch variables)”The Error action is how you intentionally fail with a message.
Select the Error step and inspect:
- Message: what gets returned/thrown
Then look at Catch steps: they can use the caught error (often via $_ERROR) to build a friendly response.
Loops: Repeat vs While
Section titled “Loops: Repeat vs While”Loops are great for transforming arrays or running repeated operations.
Repeat iterates over a list (think: for-each). While repeats until a condition becomes false (use carefully to avoid infinite loops).
Tip: prefer Repeat when you already have an array.
Repeat Properties: iterate + shape output
Section titled “Repeat Properties: iterate + shape output”With Repeat selected, check Properties:
- Repeat: the list/array you iterate over
- Output fields: what each iteration produces
- Exec: the steps that run for each item
If you want loop results in the response, make the output schema explicit here.
Parallel & Group: organize work
Section titled “Parallel & Group: organize work”Group keeps related steps together (and can help readability).
Parallel runs branches at the same time (when supported), which can speed up independent work like multiple API requests.
Tip: parallelizing only helps when tasks don’t depend on each other.
Reuse: Library actions (Include vs Exec)
Section titled “Reuse: Library actions (Include vs Exec)”Library actions let you reuse logic across multiple actions.
Include inlines steps into the current flow. Execute (Exec) runs another action as a callable unit with its own output.
TIP: Library actions are the “functions” of Server Connect: reuse them to keep endpoints small and consistent.
Wrap-up
Section titled “Wrap-up”You’ve seen the main patterns behind complex actions: containers, branching, loops, and reuse.
Pick a next tour based on what you want to do next.
Next steps
Section titled “Next steps”Pick a related tour to continue.