VWorks User Guide : Creating a protocol: advanced topics : Using JavaScript

Using JavaScript
About this topic
This topic explains how to use JavaScript in the VWorks software. For a full description of the JavaScript language, see the Mozilla Developer Center at https://developer.mozilla.org/en-US/docs/Web/JavaScript.
Read this topic if you have administrator or technician privileges. This topic assumes that you know how to write programs in JavaScript or have basic programming knowledge.
How JavaScript is used in the software
A comprehensive JavaScript engine is implemented in the VWorks software so that you can customize the software as follows:
The task parameters can change dynamically during a run based on conditions such as:
Examples of use
You can use JavaScript in the VWorks software to:
Where to write JavaScript
You can write JavaScript in the Advanced Settings area of any task or in the JavaScript task in the Startup, Main, and Cleanup Protocols. JavaScript written in any task is run differently than code written in the JavaScript task:
Any task. During a protocol run, the software will run the JavaScript first before evaluating whether the task is possible.
JavaScript task. You can add the JavaScript task to run a program that is independent of any task. During a protocol run, the software will run the JavaScript as it reaches the JavaScript task.
The following example shows JavaScript written in the Advanced Settings area of the Aspirate task. Notice that the script is written directly in the text box.
 
You can add JavaScript in the following ways:
 
About JavaScript variables
By default, the values of all variables are cleared (set to undefined) before the next protocol is run. To retain the value of all variables from protocol to protocol, select the Use global context for this protocol option in the Protocol Options tab. When the option is turned on, a variable and its value assigned in one protocol can be used by other protocols that have the same variable until you exit the software. If using the global context option, the values of variables are not reset until the software is restarted.
 
Cautions
Before running a protocol containing JavaScript, compile the protocol and run it in simulation mode.
During the compiling process, the software uses values displayed in the Task Parameters area and not the values set by JavaScript. Therefore, some errors might not be detected during compilation. The values that appear in the Task Parameters area do not reflect the effects of the JavaScript.
Be aware that JavaScript does not check pipetting volumes before the run begins. Therefore, you must make sure that the pipetting steps make logical sense. For example, the software does not alert you if a JavaScript attempts to aspirate 1 µL from a microplate well that can only hold 0.5 µL.
Related information