Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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 example in.recordID.
  • Internal Variables are created and populated by PhixFlow when certain actions happen.
    For example, _fileName is populated by PhixFlow and is available in the definition of stream attribute, when the streamset has data that is coming from a file collector. 
    See the list on the Internal Variables page.
  • User-defined variables are the variables you can create to hold data required for complex calculations in attributes or other expressions. These are 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.  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.
  • 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'

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.

ExpressionResult

do(
   $A = 5,
   $B = 2,

   $A*$B
)

Sets values for 2 $-variables: $A and$ B 
Performs simple calculation
Returns 10


do(
   $c = 10,

   $A*$B*$C
)

A different expression sets another variable value
References the $-variables from the previous expression
Returns 100

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, below.
  • to store a value from a look-up pipe, when you need the value in multiple attributes
    1. In the first attribute, look-up the value.
    2. Use a $-variable to store the value that is returned by the look-up.
    3. 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, below.


=

Variable Typing

When a variable is first used, PhixFlow will make a best guess about what type of data is stored in that variable. e.g.

$thisNumber = 4 // A Number $thisAddress = '123 Fake St' // A String Value

When PhixFlow has decided what type of data is stored in a variable, that type will not change. So in the above example,

$thisNumber = $thisAddress

will cause PhixFlow to reject the expression you are building. In some cases a type conversion function (e.g. toDate) can be used to force a value of one type, into a variable of another type.Note : in some cases, PhixFlow will be able to convert from one type to another. e.g. from an integer to a floating point value.

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.

Variable Scoping

When writing expressions that reference variables it is important to understand the scope of those variables.

A Variable (or an Attribute Name) can only be referenced in an Expression if that Variable has already had a value assigned to it.

Note : Attributes are evaluated in order, so Variables defined in an Attribute (or the attribute name itself) can be referenced in a later Attribute Expression, or in a dependent Expression that is referenced after that Attribute is evaluated.
E.g. you can refer in a pipe index Expression to a $variable if you have done a "lookup($variable)" in the Stream before that pipe reference (or in an Output Multiplier, or an Output Filter), but otherwise you can’t.


The following tables gives some guidelines for the availability of Variables, based on the PhixFlow Timing Cycle for evaluating Models.

Location of ExpressionAvailable Variables
Input MultiplierSome 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 MultiplierInternal Variables (e.g. _toDate)
User Defined Variables
Attribute ExpressionInternal 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 ExpressionInternal 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

See Also

  • No labels