terminate Function for Scripts

The terminate method allows stopping the execution of a script that is currently running.

Syntax

It is possible to stop the script execution thread. See the following syntax:

 

terminate();

 

When executing a script that includes a subscription, for example:

 

var result = subscribeValues("System1.ManagementView:ManagementView.SystemSettings.OrganizationModes.DayNight", "Value", onOrganizationModeChanged);

if (result.error) {

    console("Subscription error: {0}", result.error);

    terminate();

}

 

console("Subscription succeeded");

...

function onOrganizationModeChanged(object, values) {

    console("New value = {0}", values.value.value);

}

 

  • If the script timeout is not set (such as, Timeout = 00:00:00 hh:mm:ss), the script remains in Activity Status=Running until it is manually stopped (otherwise the subscription keeps the script alive).
  • If the script timeout is set, then the script stops when the timeout expires (Last Execution Status = Timed out).

Error Handling

Errors can occur in case:

  • The parameter is not defined.
    • An error is traced in the Script Editor (Error List expander). Also, an exception is traced in the Log Viewer.

Examples of Use

 

How to stop the script execution by calling the related method with a defined variable or any string value as parameter

    terminate(100);