Setting up the Watcher configuration file
About this topic
This topic assumes that you know how to write programs in JavaScript or have basic programming knowledge. You must also have VWorks administrator or technician privileges.

Data integrity risk! The Watcher feature may not meet the compliance requirements of your organization. Agilent advises impacted customers not to use the Watcher. The
VWorks software does not log an audit trail or provide tamper detection for the Watcher configuration file (.ini). This file type cannot be secured in the
Secure Storage Repository.
Creating the configuration file
Watcher requires a single configuration file (.ini) that contains one entry (monitoring condition) per line. Each monitoring condition entry must consist of the following four values separated by commas:
<folder to monitor>,<file filter>,<JavaScript file location>, <JavaScript function>
Figure Watcher configuration file showing an example of the four comma-separated values
Item | Value | Description |
---|
1 | Folder to monitor | The full path to the file folder that Watcher will monitor for new files. Use forward slashes ( / ) as a path delimiter. |
2 | File filter | The file name extension of the file type to be monitored. The filter applies to file name extensions only. You cannot filter by partial file names. |
3 | JavaScript file location | The full path to the JavaScript file. Use forward slashes ( / ) as a path delimiter. |
4 | JavaScript function | The function in the JavaScript file that you want to run when the desired files appear in the monitored folder. |
Configuration example—Monitoring one folder for one file type
In the following example, Watcher will monitor the Inputs folder for the file type .xml. When an .xml file is added to the folder, Watcher will run myscript.js and call the main function. The function main must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
• Contents of .ini file:
C:/VWorks Workspace/Inputs,.xml,C:/VWorks Workspace/Scripts/myscript.js, main
• Contents of myscript.js file:
function main(input_file){
print("in main: " + input_file)
}
Configuration example—Monitoring one folder for more than one file type
The Watcher configuration file (.ini) can specify multiple monitoring conditions, but each condition must be stated on a single line and consist of the four comma-separated values.
In the following example, Watcher will monitor the Inputs folder for the file types .xml and .rst (runset). When either file is added to the folder, Watcher runs myscript.js and calls the corresponding JavaScript function for the file type. The functions mainXML and mainRST must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
Figure Watcher configuration file example specifying one folder and two file types for monitoring
For this example, the myscript.js file would contain the following code:
function mainXML(input_file){
print("in mainXML: " + input_file)
}
function mainRST(input_file){
print("in mainRST: " + input_file)
}
Configuration example—Monitoring more than one folder
You can specify that more than one folder be monitored and run different scripts for different file types that appear in each folder.
Figure Watcher configuration file example specifying two folders and two file types for monitoring
Using the same script from the previous example, this configuration file would do the following:
• Monitor the InputsXML folder for new .xml files, and then call the mainXML function. The mainXML function must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
• Monitor the InputsRST folder for new .rst files, and then call the mainRST function. The mainRST function must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
Specifying the configuration file location
To set the configuration file location:
1 Select Tools > Options. The Options dialog box opens.
2 In the
Watcher Options area, click the field next to
Path to Watcher configuration file, and then click the

button that appears.
3 In the Open dialog box, select the desired location and click Open.
4 In the Options dialog box, verify the new path, and then click OK.
Related information