VWorks User Guide : Setting up and using the Watcher tool : Creating the script that Watcher will run

Creating the script that Watcher will run
About this topic
This topic assumes that you know how to write programs in JavaScript or have basic programming knowledge.
For a full description of the JavaScript language, see the Mozilla Developer Center at http://www.mozilla.org/js/.
Guidelines for creating your script
In addition to using good script-writing practices, follow these guidelines when creating a script for Watcher to run:
Define the JavaScript function correctly. The function that Watcher will run, for example WatcherMain, must take one parameter:
 
The name of the function in the script must match the function name in the Watcher configuration file (.ini).
Identify or create any other scripts that your script will call. Automation Solutions has JavaScript files with predefined objects and functions that you may use, including:
 
Provides examples on how to use the VWorks plateDB object, which can be accessed by a script. For a description of the plateDB object, see plateDB object.
Define any required global variables, such as folder paths. You should define the folder paths where processed files will be stored, such as the VWorks folder, the working folder, and an output folder, if applicable. For example, you might define the following:
var VWorksFolder    = “C:/VWorks Workspace/”
var WorkingFolder   = VWorksFolder + “WorkingFolder/”
var OutputFolder    = VWorksFolder + “Output/”
Include code at the end of the script to delete the input file from the monitored folder, if applicable. To prevent repeated processing of files upon restarting Watcher, the script should delete the input file or move it into a processed folder or output folder after processing the file.
Example script:
print("deleting input file: [" + input_file_name + "]")
DeleteFile(input_file_name);
Script example—Creating data-driven working protocols from a template protocol
This section provides example script for scenario 2 in Description. In this scenario, Watcher monitors a folder for new input files, each of which specifies the attributes of a single protocol run. When a new input file appears in the folder, Watcher runs a script to create a working protocol based on a template protocol and an input file, and then schedules the protocol.
The following script example shows a hypothetical WatcherMain function, which does following:
1
2
3
4
5
6
7
To accomplish some of these tasks, the WatcherMain function includes calls to other predefined JavaScript functions, such as inputParser and protocolEditor.
 
Related information