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 7 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.
    • In expressions, attribute names can be qualified with pipe names like this:  <pipename>.<attributename> for example in.recordID.
    • Database collectors are a special case. They generate implicit attribute names from the names of the fields returned by the database query.
  • 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. 
Sections on this page

This page summarises which variables are available in different contexts, and explains how to create and use $-variables. See also Expression Basics.

Which Variables are Available

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 multiplier

Some internal variables (e.g. _toDate)

$-variables (i.e. variables declared locally in the Input Multiplier)

Database collector SQL script

_inputMultiplier

%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.

Creating and Using $-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'

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.

ExpressionResult

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

   $A*$B
)

This expression

  • 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.
  • 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.

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:

ExpressionPhixFlow identifies data type
$thisNumber = 4integer
$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.


See Also

  • No labels