Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
Tip |
---|
To assign a string, it must be enclosed in:
|
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
) |
Anoth;er expression can reference the $A and $B variables in a different calculation. The following expression returns 100.
Code Block |
---|
do(
$c = 10,
$A*$B*$C
) |
$-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
- 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.
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.
Tip |
---|
It can be helpful to distinguish between $-variables that are:
|
title | Simple $-variable example |
---|
Adding Comments
It is always a good idea to add comments to your scripts to explain its steps. Comments 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)