Jump to Specific Step in a Different Sequence Using PostStep Callbacks

Updated Apr 22, 2026

Environment

Software

  • TestStand

In NI TestStand, when a step generates a runtime error or evaluates to a Failed result, the execution engine follows its default behavior. Typically, this includes displaying a runtime error dialog, stopping execution, or moving the execution to the Cleanup group.

 

TestStand provides Sequence File callbacks that allow you to intercept such execution events and modify the execution flow programmatically. In particular:

 

  • SequenceFilePostStepRuntimeError is invoked after a step generates a runtime error
  • SequenceFilePostStepFailure is invoked after a step completes with a Failed result

 

By leveraging these callbacks and explicitly setting the NextStepIndex property of a Sequence, you can redirect execution to any step of any sequence in the call stack. This approach allows you to override the default behavior and implement custom recovery or continuation logic.

 

This tutorial demonstrates two independent flow-control scenarios within the same Main sequence: one for handling runtime errors and another for handling step failures.

 

Table of Contents

 

 

 

Creating the Test Sequence

 

Create a sequence file with a Main sequence containing:

    • Initial passing steps
    • A step that generates a runtime error (for example, a subsequence call)
    • Several intermediate steps (e.g., Action 1, Action 2, Action 3)
    • A step that produces a Failed result
    • Additional steps following the failure (e.g., Action 5, Numeric Limit Test

 

The sequence may look like this:

 

Example Sequence

 

Please note that the following steps are based on the sequence shown in the previous image. The specific details within the subsequences do not matter; our requirement is simply for one to produce an error and another to result in failure.

 

[Return to TOC]

 

Handling Runtime Errors

 

 

  1. Add the SequenceFilePostStepRuntimeError callback to the sequence file.


    This callback is invoked immediately after a runtime error occurs. At this point, the execution is no longer in a normal state, so the first goal is to stabilize the execution context before redirecting flow.


    Add the following expression:

     

    RunState.Caller.RunState.ErrorReported=True

     

  2. This marks the error as handled and prevents TestStand from displaying the default runtime error dialog.

 

  1. Still inside SequenceFilePostStepRuntimeError, add:

    RunState.Caller.GotoCleanup=True

    Because we set ErrorReported=True we must determine the execution behavior programmatically. In our example case, we want to make the caller sequence go to clean up and the MainSequence go to a specific step, which is what we're going to do next.
  2. After stabilizing the execution context, explicitly redirect execution by adding:

    RunState.Main.NextStepIndex=RunState.Main.Sequence.Main["Action 3"].StepIndex

    At this stage, it is now safe to override the execution flow. This expression forces TestStand to resume execution at the step "Action 3", skipping any intermediate steps such as Action 1 and Action 2.

    Note: We use the step name here for demonstration purposes, you could directly set NextStepIndex to a numeric constant. In cases where more than one step has the same name, this approach might not be so reliable. The most robust way would be to get the step unique ID (Step.TS.Id), but that is a more complex approach and is out of the scope of this tutorial. 

    If you were to use the unique ID, the expression above would look like this:

    RunState.Main.NextStepIndex = RunState.Main.Sequence.GetStepByUniqueId("ID#:HXFm/1k68RGW/uhivs+EzB").StepIndex


    Where "ID#:HXFm/1k68RGW/uhivs+EzB" is the unique ID of the Action 3 step.

 

Your sequence should look like this:

 

SequenceFilePostStepRuntimeError

 

[Return to TOC]

 

Handling Step Failures

 

  1. Add the SequenceFilePostStepFailure callback to the sequence file.

     

    This callback is invoked when a step completes with a Failed result. Unlike runtime errors, the execution context remains valid, so fewer steps are required to redirect execution.

     

  2. Inside SequenceFilePostStepFailure, add:

    RunState.Main.GotoCleanup=False
    

    This prevents TestStand from automatically transferring execution to the Cleanup group after a failure, allowing execution to continue within the Main sequence.

  3. Redirect execution by adding:

    RunState.Main.NextStepIndex=RunState.Main.Sequence.Main["Numeric Limit Test 2"].StepIndex
    


    Since the execution context is still valid, the flow can be redirected directly. This causes TestStand to skip intermediate steps (such as Action 5) and resume execution at "Numeric Limit Test 2".

 

Your sequence should look like this:

 

SequenceFilePostStepFailure

 

[Return to TOC]

 

Executing the Sequence

 

Execute the sequence using Run MainSequence.

 

If you build and sequence similar to the one above, your execution view should look like this when the execution finishes.

 

 

 

[Return to TOC]

By following the above steps, you can exit out of certain subsequences and go to specific steps in different sequence files when a specific condition is met. 

Please, refer to the attached files for a sequence that reproduces the steps described above.