PhixFlow Help
Scripting Basics
Introduction
Many fields can be configured with scripts and simple expressions however for the purposes of the examples here we have assumed that the reader is configuring a Stream Attribute field unless otherwise stated. This field is in no way special and in general all of the scripting elements and techniques described are available in all of the dynamic fields. Any special cases are documented on the help screen describing the individual form.
Assigning a literal value to a field
The most basic expressions simply assign a constant value to the field. For example these three expressions assign the integer 3, the floating point number 3.2 and the string "Hello" to the field:
Expression | Result |
---|---|
3 | 3 |
3.2 | 3.2 |
"Hello" | "Hello" |
Note that if you want to assign a string value (as in the last example) then the characters must be enclosed in either single 'Hello' or double "Hello" quotes.
Parameter TypesÂ
When writing expressions it is important to consider the type of the result. For example, if you have written a Stream Attribute expression to return the integer 3 but have defined the type of the Stream Attribute to be a String then PhixFlow will stop and report the error when the expression is evaluated. The full list of types handled by PhixFlow is shown below. It's not necessary to understand the meaning of the individual types at this stage, however just be aware that the different types exist.
Type | Description |
---|---|
Array | A list values, e.g. [1,2,3]. For details about what other values arrays can hold and Array handling in general see Arrays and Record Sets. |
Date | A date. For details about date manipulation functions go to Date Functions. |
Datetime | A date and time. For details about date manipulation functions go to Date Functions. |
Float | A floating point number, e.g. 3.2 or 3.0 or 0.0 |
Integer | An integer, e.g. 3 or 0 |
Number | An integer or floating point number |
String | A string value, e.g. "Hello" or the empty string "" |
Boolean | A logical value of either true or false. Note that any non-null, non-zero value is treated as true |
Regular Expression | Regular Expressions allow string patterns to be expressed. See Regular Expressions for more details |
Assigning values from a Pipe
One of the most common type of expression is to fetch the value returned by a Pipe. This is simply done by suffixing the Pipe name with the name of the attribute to be returned. E.g.
in.accountRef
This expression causes PhixFlow to look at the pipe named "in" and return the value in the field called "accountRef". Note that it is possible for the above expression to return multiple values however this more advanced topic is covered in Arrays and Record Sets.
If the name of the attribute whose value you want has to be calculated based on other factors then the attribute name can be assigned to a variable (see the section below on mulitline statements and $-variables) and the variable used in place of the attribute name itself e.g.
in.$attrName
If the name of the attribute whose value you want contains characters that would otherwise be invalid you can either assign that name to a variable (see the section below on multiline statements and $-variables) and use the variable instead of the actual attribute as discussed above or simply enclose the name in quotes e.g.
in.'account-ref'
Mathematical Operators (+, -, *, /)
Several values can be combined using the usual basic mathematical operators. For example when in.numProducts has the value 9:
Expression | Result |
---|---|
in.numProducts + 3 | 12 |
in.numProducts - 3 | 6 |
in.numProducts * 3 | 27 |
in.numProducts / 3 | 3 |
The usual calculation precedences apply i.e. * and / operations are carried out before + and -. When the mathematical statements involve multiple calculations, brackets () can be used to force the correct processing order:
Expression | Result |
---|---|
3 * 3 + 3 | 12 |
3 * (3 + 3) | 18 |
String Concatenation (+)
The + operator also serves as the string concatenation operator i.e. joins strings together. For example if in.customerName returns "Smith" and in.title returns "Mr"
Expression | Result |
---|---|
"Hello" + " to " + "you" | "Hello to you" |
"Dear " + in.title+ " " in.customerName + "," + | "Dear Mr Smith," |
Note that if you attempt to use + to concatenate a String and a numeric value (e.g. an Integer ) then PhixFlow will simply treat the number as a string and concatenate it. E.g.
Expression | Result |
---|---|
"Hello" + 3 | "Hello3" |
"4" + 3 | "43" |
Multiline statements and $-variables
Often there is a need to work out the result of a more complex expression which may require several different statements to be evaluated first. To group several statements together in this way, you should make use of the do() function. In nearly all multiline statements, it is also very convenient to assign the value of an expression to a $-variable which may then be used later in the expression. E.g.
Expression | Result |
---|---|
do ( Â Â $name = in.customerName, Â Â $title = in.title, Â Â $salutation = "Dear", Â Â $result = $salutation + ' ' + $title + $name ) | "Dear Mr Smith" |
Please note that every statement within the do() function (except the last) ends in a comma ",".
Please also note that the value of an expression (e.g. the value that will be assigned into a Stream Attribute ) is the value of the last statement to be evaluated. In the above example, this seems very trivial as the last statement to be evaluated is the last line. However when we look at Conditional Statements the last statement evaluated is not always the last statement in the expression. For example:
Expression | Result |
---|---|
| 45 if the customer's name is "Smith" but otherwise the value 36. |
Adding Comments
In longer scripts (and even short scripts) it is a good idea to add comments to remind yourself (and anyone else who may need to modify the script in future) what steps are being followed. For short, 1 line comments, just prefix the line with // and for longer, multiline comments, enclose the lines in /* .... */. For example:
/* Get the discount rate that should apply to the calls which match the filter conditions */ $discountRate = discount.rate, // Now apply the discount $value = $value * ( 1 - $discountRate)
The lines above are comments and are ignored by PhixFlow.
See Also
Please let us know if we could improve this page feedback@phixflow.com