VBScript

VBScript scripting in Switch is intended primarily for communicating with other applications or with operating systems services from within Switch. A script object representing the Switch application provides access to key variables and functions, including the metadata context of the job being processed. VBScript is available on Microsoft Windows only. Refer to the Scripting overview for more background information.

Note:

Switch does not support the JScript language (a scripting language also available on Microsoft Windows).

Language reference

Comprehensive reference and introductory information about VBScript can be found on the Microsoft web site and in widely available literature. Use the search term "VBScript" when looking for information on the web. Don't confuse VBScript with the Visual Basic programming language (a full-featured programming language and development environment offered by Microsoft) which is quite distinct from VBScript.

A good starting page regarding VBScript on the Microsoft web site is the page on Windows Script in the Microsoft MSDN section. This page links to a full VBScript language reference and to a script repository that contains numerous practical example scripts.

Extensions reference

Switch provides a number of Switch-specific classes and functions to support accessing key Switch variables and functions, including the metadata context of the job being processed. Refer to the Switch scripting API for reference documentation about these extensions.

The Switch scripting API reference documentation uses the JavaScript syntax and semantics to describe its various classes and functions. In almost all cases, there is a straightforward correspondence with VBScript syntax and semantics. The following sections highlight some issues to keep in mind while reading the scripting API documentation.

API restrictions

Not all of the classes and functions described in the scripting API are available when using VBScript. Specifically, the classes and functions in the "Utility", "XML", "Database" and "Network" modules are not available. If you need the functionality in these modules, you have to use the native VBScript capabilities.

For example, the "Utility" module provides "File" and "Dir" classes to work with files and folders. In VBScript this functionality is available through the "FileSystemObject".

Functions versus procedures

In JavaScript there is no difference between calling a function (something that returns a value) and calling a procedure (something that does not return a value). In VBScript there is a difference and this is one of the most common pitfalls when translating JavaScript code into VBScript.

For example, here's how to call two of the Job class functions (defined in the Switch scripting API) in JavaScript:

job.addEmailAddress("test@test.com");
theResult = job.getPrivateData("key");

In VBScript procedure calls do not use parenthesis to enclose the arguments, so the above translates to:

job.addEmailAddress "test@test.com"
theResult = job.getPrivateData("key")