This page summarises which variables are available in different contexts, and explains how to create and use $-variables. See also Expression Basics.
The following tables gives some guidelines for the availability of variables, based on the PhixFlow Timing Cycle for evaluating analysis models.
Location of Expression | Available Variables |
---|---|
Input multiplier | Some internal variables e.g. _toDate $-variables declared locally in the input multiplier |
Database collector SQL script | %USERNAME%, %PASSWORD% $-variables |
Output Multiplier | internal variables e.g. _toDate $-variables |
Attribute expression | internal variables e.g. _toDate All <pipeName> values e.g. inpipe.accountVal All _out.value where value is the name of the attribute and it is before the current attribute in the stream All user defined variables created in a prior attribute expression |
Output filter expression | internal variables e.g. _toDate All _out.attribute values All user defined variables created in any Attribute expression |
Pipe index expression on a lookup pipe | internal variables <pipename>.attribute - the name on an input pipe All _out.value where value is the name of the attribute and it is before the current attribute in the stream |
Variable Scoping
When writing expressions that reference variables it is important to understand whether PhixFlow has "seen" the variable yet. This is the scope of the variable.
In a stream, output multiplier or output filter, the attributes have a specified order. When you run analysis on a model, PhixFlow processes each attribute in order, evaluating their expressions. This means you cannot reference:
- an attribute name before PhixFlow has processed it. So in the first attribute in a stream, you cannot use a value from the third attribute in the stream.
- a $-variable before PhixFlow has processed the expression where it is set.
You can only reference:
- an attribute name in a subsequent attribute
- a $-variable after it has been set or evaluated.
Internal Variables
PhixFlow has a list of Internal Variables. For example, some common ways to reference attributes in a stream:
Variable | Syntax | Example | Details |
---|---|---|---|
. | <pipe_name>.<attribute_name> | in.AppleHarvestDate | Indicates the source of the attribute is the incoming pipe. The default name for a pipe is "in". |
_out | _ | _out.AppleHarvestDate | PhixFlow processes stream attributes in the specified order. Use _ If your expression is not working, check to make sure anything it references has already been processed or evaluated by PhixFlow. If the expression is referencing something that will be processed later, PhixFlow will not be able to evaluate the expression. |
toDate | see toDate | if( _out.AppleHarvestDate < _toDate('20210101'), 1, 0) | In this case one of the arguments in an if statement is an internal variable, that indicates the date up-to which PhixFlow will process a record. |
In applications, some commonly-used internal variables are:
Variable | Syntax | Example | Details |
---|---|---|---|
_grid | grid.<grid_name> | ||
_form | form.<form_name> | ||
_context | context.<context_name> |
The internal variables that you can use in an expression depend on context. Remember to check the properties page for the item on which you are working; see Property Tabs.
Creating and Using $-variables
Defining a $-variable
- All user-defined variables must start with the $ character.
- For multi-word variable names, use no spaces and camel case.
- It can be useful to know whether a variable is used in other expressions. As there is no way to check this, we recommend using the following naming convention:
- To distinguish between $-variables that are:
- only used in the current expression or attribute, use a lowercase first letter, for example
$percent
.
These are sometimes called local. - used in other expressions or attributes, use an uppercase first letter, for example
$Percent
.
These are sometimes called global.
- only used in the current expression or attribute, use a lowercase first letter, for example
PhixFlow assumes that you are declaring a variable and setting its value the first time it occurs in the expression.
$localVar = 'Smith' $GlobalVar = 'St.John-Smith'
Using $-Variables in Expressions
In expressions that have complex calculations, you may need a variable to hold the result of a calculation. You can then reference the variable later in the expression, or in other attribute expressions for the same stream.
The following expression uses do() function and $-variables for a simple calculation.
Expression | Result |
---|---|
| This expression
|
| A different expression
|
When to Use $-variables
$-variables are not really needed in simple calculations. They are useful:
- in forEach loops
- calculating attibute names from pipes; see Assigning Values From a Pipe.
- to store a value from a look-up pipe, when you need the value in multiple attributes
- In the first attribute, look-up the value.
- Use a $-variable to store the value that is returned by the look-up.
- When you need the value in another attribute, reference the $-variable instead of repeating the look-up.
- in complex expressions, to break up multiple consecutive functions into separate lines. In this case, use a $-variable to store the intermediate values; see Multiline Statements and $-variables.
Variable Typing
When a variable is first used, PhixFlow makes a best guess about what type of data is stored in that variable; see Parameter Types. For example:
Expression | PhixFlow identifies data type |
---|---|
$thisNumber = 4 | integer |
$thisAddress = '123 Fake St' | string |
When PhixFlow has decided what type of data is stored in a variable, you usually cannot change the type. PhixFlow will reject an expression that equates different types, such as:
$thisNumber = $thisAddress
The cases where you may be able to change a data type are
- integer to a floating point value: PhixFlow may be able to convert between these.
- by using type conversion function, such as toDate. This forces a value of one type into a variable of another type.