Introduction
PhixFlow has 3 different kinds of Variable which can be referenced in Attribute Expressions and other places where expressions are allowed. These are :
...
Overview
When writing expressions and scripts in PhixFlow, you can use different types of variable.
- Attribute names are like the column headings in a spreadsheet.
- You can reference an attribute using its name in other attributes, expressions and file collectors.
- Database collectors are a special case. They generate implicit attribute names from the names of the fields returned by the database query.
- In expressions, attribute names can be qualified with pipe names like this:
<pipename>.<attributename>
for examplein.recordID
.
- Internal Variables are created and populated by PhixFlow when certain actions happen. E.g.
For example,_fileName
is populated by PhixFlow and is available in the definition of Stream stream attribute, when the streamset has data that is coming from a fileCollector. A full list of Internal Variables, and how they are populated can be found herefile collector.
See the list on the Internal Variables page. - User Defined Variables - These are defined variables that are defined by the user, and can be used the variables you can create to hold data required for complex calculations in attributes or other expressions. Attribute Names - These are the attribute names that are defined as part of a Stream which are subsequently available for use in other attributes or expressions. Attributes can referred to in File Collectors, and implicit attribute names come from database collectors as a special case where these are the names of the fields returned by the DB Collector query. Attribute names can be qualified with pipe names e.g. pipename.recordID.
Defining a Variable
...
- prefixed with a $ character, so are called $-variables.
This page explains how to create and use $-variables.
Defining a $-variable
A $-variable must start with the $ character. By convention, Camel case naming convention is used (Camel case is a convention where names are made up of multiple words, with no spaces and the first letter of each word is capitalised. e.g. ThisIsCamelCase) when giving a variable a name, and variables that are local to the current function or expression should start with a lower case letter after the initial $ character. Variables whose scope extends beyond the current attribute expressions should start with an upper case letter after the initial $ character.
A User Defined variable need not be declared. The first time a variable is referred to in an expression, it is assumed that the variable is being declared and a value is being assigned to it.
...
We recommend you use a consistent style for $-variable names.
- To distinguish between $-variables that are:
- only used in the current attribute, the inital character is lower case, for example
$percent
- also used in another attribute, the initial character is capitalised, for example
$Percent
.
- only used in the current attribute, the inital character is lower case, for example
- For multi-word names, use no spaces and camel case, for example
$ThisIsCamelCase
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'
Excerpt | ||||||
---|---|---|---|---|---|---|
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. In PhixFlow you can use a $-variable for this, by prefixing the variable name with the $ symbol. The following expression uses do() function.
When to Use $-variables $-variables are not really needed in simple calculations. They are useful:
|
=
Anchor | ||||
---|---|---|---|---|
|
When a variable is first used, PhixFlow will make a best guess about what type of data is stored in that variable. e.g.
...
A further discussion of type assignments and full list of types is available in the Parameter Types section on the help page for Scripting Basics and a discussion on how complex expressions can be defined for attributes is available here.
Anchor | ||||
---|---|---|---|---|
|
When writing expressions that reference variables it is important to understand the scope of those variables.
...
Location of Expression | Available Variables |
---|---|
Input Multiplier | Some Internal Variables (e.g. _toDate) User Defined Variables (i.e. variables declared locally in the Input Multiplier) |
Database Collector SQL script | _inputMultiplier %USERNAME%, %PASSWORD% User Defined Variables |
Output Multiplier | Internal Variables (e.g. _toDate) User Defined 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 |