---
url: >-
  /statelake/scripting-reference/functions-and-procedures/program-control-functions/stopexecution.md
---

# StopExecution

**StopExeution** cancels the execution of the **Map** (or **Custom Script**) immediately after the current script, and by default, cancels any subsequent step(s) in that **Action**.

Any code lines in the script following this function will still be executed. Use **Exit** to stop the processing of the remainder of the script. Please review [Exit](/statelake/scripting-reference/functions-and-procedures/program-control-functions/exit) for more information.

Using this procedure will cause the status of the **Action** to be set to cancelled (for **Logs** and notifications), and the **Log** will be **YELLOW**.

If the **Action** has one or more **Action Steps**, any subsequent step(s) will not execute. This is the default behaviour.

To allow execution of any subsequent **Action Step**, either see below, or use the **CancelExecution** procedure. Refer to [CancelExecution](/statelake/scripting-reference/functions-and-procedures/program-control-functions/cancelexecution) for more information.

**Declaration**: Procedure StopExecution;

An example is as below.

```pascal
procedure ScriptEvent(var Value:Variant);
var aInt :integer;
begin
  aInt := 2;
 if aInt <> 10 then
 begin
    LogInfo('This is the 1st line before STOP.');
    LogInfo('This is the 2nd line before STOP.');
    LogInfo('Next line will STOPEXECUTION. . . .');

    StopExecution;                        //subsequent lines will ALL execute;
    LogInfo('This is the 1st line after STOP.');
    LogInfo('This is the 2nd line after STOP.');
    LogInfo('Next line will EXIT . . . .');

    Exit;                                   //subsequent lines will NOT execute;
 //processing has now ceased and nothing further will execute
    LogInfo('This is the 1st line after EXIT.');
    LogInfo('This is the 2nd line after EXIT.');
 end;
end;
```

## Execute Next Action Tick Box

The **Action Steps** to be executed by an **Action** can be controlled by setting, or clearing, the check-box **Execute next Action Step even if previous one is cancelled** (on the **Action's Execution** tab).

If this box is left unticked, then by default, any **Action Steps** which follow a **StopExecution** will not be executed, and the resulting **Log** will be **YELLOW**.

However, if this box has been ticked, then one of three (3) things will happen -

* If the box is ticked but there are no following steps after the step that called the **StopExecution**, then the resulting **Log** will be **YELLOW**.
* If the box is ticked, but the last step also includes a **StopExecution**, then the resulting **Log** will have a cancelled status, and will be **YELLOW**.
* If this box has been set with a tick, and there are one or more following steps, then the **Action** will process those steps, and ignore the status of the step that called the **StopExecution**. Therefore, successfully processed steps which follow the step calling the **StopExecution** will cause the **Log** to have successfully completed status, and show to be **GREEN**.

## Action.IgnoreCancel

The check-box corresponds to the **Action.IgnoreCancel** property, and this can be set or cleared via script.

As per the following example, when it is wanted that a multi-step **Action** show as cancelled in the **Logs**, then the property could be cleared part way through the **Action** (at run-time) so that **StopExecution** will have full effect.

```pascal
if (SampleDataSource.RecordCount = 0) then
begin
  Action.IgnoreCancel := False;
  StopExecution;
end;
```
