Skip to content
  • There are no suggestions because the search field is empty.

How-To: Test Write an Output

Testing Connection Outputs and Writing Test Data & Expressions

The Common Error

Expression engine failed to calculate expression. SyntaxError: Unnamed:2:10 Expected ; but found :

This error is often encountered by a quick test write. This article will explain why, and how to use a test write block effectively to write to outputs

The Test Write Block and Proper Use

The Test Write block is available in the configuration page of connection outputs to allow the user to simply write to an output to confirm its functionality.

This is a block of executable code that will be run on pressing the “Write Output” button. Primitive data types (strings, numbers, booleans) and arrays can be entered here and submitted directly from the test write. Other JavaScript expressions may also be executed to arrive at primitive data types, arrays or non-array-objects. To submit non-array-objects, they must be wrapped in parentheses, otherwise, the error above will be raised.

References from inputs, instances, system, and variables may also be submitted to the test write.

Test Writes are Evaluated as Scripts

The Test Write block is capable of executing JavaScript. Any JavaScript expressions written in this block will be captured and run as a script before the final result being published to the specified output.

This scripting mechanism has a few rules that are slightly dissimilar to how JavaScript is conventionally run. The final expression executed by the engine is returned as a value, so the user is obligated to use an “implicit return.” This implicit return essentially returns the last data that the script uses, but does so without the use of the “return” keyword. This is how primitive datatypes can be written in this block without further effort.

The curly-brace “{}” serves two purposes in JavaScript – it can either enclose a block of code like in an “if-then” expression or a loop, or it can be used to define an object like {“key”:”value”}. By default, the former is expected over the latter. If an object is written into the test write without encapsulation in parentheses, the interpreter encounters a badly formatted code block rather than an object. Encapsulating the object with parentheses specifies the scope, indicating to the interpreter that this should be treated as an object ({“key”:”value”}).