Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
In stream attribute 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. In PhixFlow you can use a $-variable for this, by prefixing the variable name with the $ symbol.
Tip |
---|
It can be helpful to distinguish between $-variables that are:
|
title | Simple $-variable example |
---|
The following expression sets 2 $-variables $A
and$ B
, then uses them in a simple calculation that returns 10.
Code Block |
---|
do(
$A = 5,
$B = 2,
$A*$B
) |
Another expression can reference the $A and $B variables in a different calculation. The following expressin returns 100.
Code Block |
---|
do(
$c = 10,
$A*$B*$C
) |
$-variables are not really needed in simple calculations. They are useful:
- in forEach loops
- when using look-up pipes
- 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, below.
Assigning Values From a Pipe
One of the most common type of expression is Pipe then can be assigned variable (see the section below on mulitline statements and $-variables) and the variable used in place eg.If the name of the attribute whose value you want contains characters that would otherwise be invalid you can either (see the section below on multiline statements $-variables) and as discussed above or simply e.g. i.e. can be used : i.e. joins String numeric value, such as an IntegerMultiline Statements and $-variablesAdding Comments
It is always a good idea to add comments to your scripts to explain its steps. These help anyone who needs to modify the script in future.
There are two ways to tell PhixFlow that a line is a comment, and can be ignored.
//
short comments up to 1 line
/* <comment> */
For example:
/*
Get the discount rate that should apply to the calls that match the filter conditions
*/
$discountRate = discount.rate,// Now apply the discount
$value = $value * ( 1 - $discountRate)