Programs
In a Script Step you can use the full range of FlowScript statements.
Variable declarations
Variables are declared using the let
keyword and re-assigned using the set
keyword. Because FlowScript is an implicitly typed language, you cannot declare a variable without also assigning it.
Return statement
To return a value from a FlowScript, use the return
keyword. The Flow Designer checks to make sure that each branch of a FlowScript returns a value.
Conditional statement
Conditional statements are written using the if/elseif/else keywords.
When the body of a conditional clause consists of only one statement, it is possible to omit the curly braces and use the colon (:) sign instead.
Loops
Loops are written using the for
and in
keywords. You can loop over table variables, strings (one iteration per character in the string) and numerical ranges.
Table example
String example
In order to exit a loop prematurely, you can use the break;
statement. In order to exit the current iteration and jump right into the next one, use the continue;
statement.
If the body of a loop consists of only one statement, you can omit the curly braces and use the colon (:) sign instead.
NOTE: To support backward compatibility with previous versions of Novacura Flow, the do
and done
keywords are also supported in lieu of the opening and closing curly braces.
Index loops
To loop over a range of indexes, use the range(start, count)
function.
Type declarations
It is possible to define types in FlowScript programs. A type defines the structure of a record (or table) variable. Types are defined like this:
When creating a new record based on a type, use the following syntax:
Types can have nested structures:
Types can also refer to other types:
Types always define the structure of record variables. However, by adding the multiplier (*) unary operator, you can convert a type into the corresponding table type:
The multiplier (*) unary operator can also be used when initializing a record:
It is possible to define default values for type fields. If a default value is given, the field does not have to be initialized.
It is possible to use nil values for type fields which themselves are records. nil values are only permitted for such cases; simple or table values cannot be nil.
Automatic types
Each record and table variable in a workflow can also be used as a type. This is useful when you need to programmatically create a record that matches the output from a machine step or some other workflow step. Automatic types are prefixed with the dollar sign ($). For record a variable myRecord
, the automatically created type will be named $myRecord_type
For a table variable myTable
, the automatically created type will be named $myTable_rowtype
.
Function declarations
Functions are declared using the let
and function
keywords.
For a single-parameter function, no parentheses are needed around the argument list. For a single-statement bodied function, the curly braces, as well as the return
keyword, can be omitted.
If no parameter type is given for a function parameter, it is assumed to be a simple value. For complex values (records and tables), the syntax is similar to that of type definitions:
If no return type is declared for a function, Flow tries to infer the return type based on the function body. It is also possible to specify an explicit return type.
If recursion is required (i.e. a function that calls itself), return types MUST be explicitly specified. If such a function returns a simple value, the return type should be specified using the simple
keyword.
NOTE: To support backward compatibility with previous versions of Novacura Flow, the do
and done
keywords are also supported in lieu of the opening and closing curly braces.
Errors
If you need to raise an error from a FlowScript, use the error
keyword.
Parsing Example
The following FlowScript program example will take a table with one string column and parse it into a table with several columns. It will split columns based on a column delimiter and take the right-side value by using a key-value delimiter.
Last updated