Script Flow Control Functions

exit()

function exit([message[, faultCode]]);
Description Immediately terminates the running script, marking it as successfully completed
Parameters
  • message – optional string to be added to the script’s Event Log
  • faultCode – optional fault code number
Returns The script exits immediately with no return
Required Libraries None
Example

exit(“The script exited with code: “, 9005); // Exit and add a message and fault code to the Event Log

exit(); // Exit with no logging

 

invoke()

function invoke(scriptName [, arguments]);
Description Invokes a script by name as eval() (when no arguments are included) or as a function call (when arguments are included)
Parameters
  • scriptName – name of the script to run
  • arguments - optional Javascript object in the form {paramName : value, …}
Returns Returns whatever value/object the invoked script returns
Required Libraries None
Example

// Executing within script A

// Trigger execution of script B

var ret = invoke(“scriptB”, {argName : argValue});

log.info(“Script B returned: “ + ret.toSource());

 

// Continue executing within script A

 

runAfter()

function runAfter(scriptName, delay [, arguments]);
Description Queues a script for the current device that will begin execution after the specified number of seconds. This script is useful for gathering diagnostic results after triggering a diagnostic that requires some amount of time to complete.
Parameters
  • scriptName – name of the script to run
  • delay – number of seconds to delay before allowing the script to run
  • arguments - optional Javascript object in the form {paramName : value, …}
Returns Returns whatever value/object the invoked script returns.
Required Libraries None
Example

// Run diagnostics

set(“InternetGatewayDevice…diagA.Enable”, true);

 

// Wait 10 seconds then get the diagnostic results

var results = runAfter(“Get DiagA Results”, 10);

log.info(“Diagnostic A Results: “ + results);

 

runInNextSession()

function runInNextSession(scriptName [, arguments]);
Description Queues a script for the current device to be executed the next time the device informs.
Parameters
  • scriptName – name of the script to run
  • arguments - optional Javascript object in the form {paramName : value, …}
Returns None
Required Libraries None
Example

// Run diagnostics

set(“InternetGatewayDevice…diagA.Enable”, true);

 

// Read the diagnostics results the next time the device informs

var results = runInNextSession(“Get DiagA Results”);

 

terminateSession()

function terminateSession();
Description Terminate this session after the current script completes. All pending scripts will be deferred until the next inform.
Parameters None
Returns None
Required Libraries None
Example

// Script A is executing…

terminateSession(); // Terminate the session once this script completes

// Script A continues executing until completion

 

terminateSessionNow()

function terminateSessionNow();
Description Terminate this session immediately. All pending scripts will be deferred until the next inform
Parameters None
Returns None
Required Libraries None
Example

// Script A is executing…

terminateSessionNow(); // Terminate the session right here

// This code will NOT be executed