4.1 Building State Machine Projects in Studio
Key Takeaways
A State has Entry, Exit, and Transition(s) sections; a Final State has only an Entry section.
A state machine has exactly one initial state but can have more than one Final State.
A transition has a Trigger, a Condition, and an Action; after the trigger completes, the first true condition wins, and the source Exit runs before the transition Action.
Choose a state machine for named stages that repeat or recover to earlier stages; choose a flowchart for forward-moving decision logic.
4.1 Building State Machine Projects in Studio
Core Concept: A state machine is a workflow type that is always in exactly one of a finite set of states. It moves between states along transitions whose conditions (and optional triggers) decide the next state. REFramework is the best-known example, but the exam description also asks you to describe the components of state machines and build your own. That means knowing what each part does and when a state machine is a better fit than a flowchart.
The Building Blocks
Studio provides two activities specific to state machines, under Workflow > State Machine, plus the State Machine container itself:
| Element | Sections | Rules |
|---|---|---|
| State Machine (container) | Holds the states and the Start node | Created with New > State Machine on the Design tab, or by adding a State Machine activity |
| State | Entry, Exit, Transition(s) | Entry runs when the state is entered; Exit runs when the state is left |
| Final State | Entry only | Ends the state machine; it has no Exit section and no outgoing transitions |
| Transition | Trigger, Condition, Action | Connects a source state to a target state; the Action runs while moving |
Two structural rules are easy to test:
- A state machine has exactly one initial state, the one connected to the Start node.
- It can have more than one Final State, for example Completed and Cancelled.
How a transition is chosen
After a state's Entry section finishes, the state machine evaluates its outgoing transitions:
- If a transition has a Trigger (an activity such as a Delay or an event wait), the transition waits for that trigger to complete. Transitions without a trigger are ready immediately.
- Once the trigger has completed, its Condition is checked. A transition with an empty condition is treated as true.
- The first transition whose condition is true is taken. The source state's Exit section runs, then the transition's Action, and then the target state's Entry.
Several transitions can share the same trigger and differ only in their conditions. REFramework's Process Transaction state works that way: Success, Business Exception, and System Exception have no triggers and are separated only by their conditions.
Worked Example: A Guess-the-Number Machine
UiPath's own documentation uses a guessing game to show all the parts:
- Initializing Random Number (initial state). The Entry section contains
RandomNumber = New Random().Next(1, 100). - Guess Number (state). The Entry section contains an Input Dialog that stores the user's value in
InitialGuess. - Transition Try Smaller, from Guess Number back to itself. Condition
InitialGuess > RandomNumber; the Action shows a "too big" message. - Transition Try Bigger, from Guess Number back to itself. Condition
InitialGuess < RandomNumber; the Action shows a "too small" message. - Transition Correct Guess, from Guess Number to a Final State. Condition
InitialGuess = RandomNumber; the Final State's Entry congratulates the user.
This shows three patterns you will reuse: a self-transition for loops, conditions that divide possibilities between transitions, and a Final State to end.
When to Choose a State Machine
| Use a state machine when... | Use a flowchart when... |
|---|---|
| The process has clear, named stages that can repeat (initialize, fetch, process, finish) | The logic is a decision tree that mostly moves forward |
| Recovery means going back to an earlier stage, as REFramework does after a System Exception | Loops are local and simple |
| Events or timers decide what happens next, as in attended waiting stages | No event waits are needed |
| You want each stage's cleanup in an Exit section | Cleanup can be ordinary activities |
A state machine is a poor fit for a short linear task: the extra states add ceremony without adding control.
Design Practices
- Name states and transitions with their business meaning. The names appear on the designer arrows and in logs, which makes debugging easier.
- Keep states thin. Put real work in invoked workflows, as REFramework does with
Process.xaml, so the state machine shows only the control flow. - Make conditions mutually exclusive. If two transitions can both be true, the outcome depends on evaluation order, which is hard to review.
- Declare shared variables at the state machine level. Variables scoped to a single state are not visible to transition conditions that leave other states.
- Always provide a way out. Every non-final state should have a reachable path to a Final State, or the job can loop forever.
- Use triggers for waiting, for example a Delay trigger on a retry-later transition, instead of busy-wait loops inside Entry sections.
Which statement about UiPath state machine structure is correct?
A state machine can have several initial states but only one Final State.
A Final State contains Entry, Exit, and Transition sections like any other State.
Transitions contain Entry and Exit sections, while States contain Trigger and Condition sections.
A state machine has one initial state, may have several Final States, and a Final State has only an Entry section.
A state has three outgoing transitions with no triggers. After the Entry section completes, in what order does the state machine run the remaining pieces for the chosen transition?
The source state Exit section, then the transition Action, then the target state Entry section.
The transition Action, then the source state Exit section, then the target state Entry section.
The target state Entry section, then the source state Exit section.
Only the transition Action; Exit sections run when the whole state machine ends.
Which process is the best fit for a state machine rather than a flowchart?
A five-step sequence that opens a browser, downloads one report, and closes.
A process with named stages that repeat, can return to an earlier stage to recover, and wait for events before moving on.
A simple If/Else validation with no loops.
A data transformation done in a single LINQ expression.
Sections you finish are checked off in the contents.