Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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:

...

TypeDescription
ArrayA 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.
DateA date. For details about date manipulation functions go to Date Functions.
DatetimeA date and time. For details about date manipulation functions go to Date Functions.
FloatA floating point number, e.g. 3.2 or 3.0 or 0.0
IntegerAn integer, e.g. 3 or 0
NumberAn integer or floating point number
StringA string value, e.g. "Hello" or the empty string ""
BooleanA logical value of either true or false. Note that any non-null, non-zero value is treated as true
Regular ExpressionRegular Expressions allow string patterns to be expressed. See Regexp ToDelete for more details

Using $-variables  in Calculations
Anchor

...

dollarvar-

...

intro

...

dollarvar-

...

intro

In stream attribute expressions that have complex calculations, you may need a dummy 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.

...

Panel
titleSimple $-variable example

The following expression sets 2 variables A and B, then uses them in a simple calculation that returns 10. To make these variables reusable in other expressions, they are prefixed with the $ symbol. returns a value of 10

Code Block
do(
   $A = 5,
   $B = 2,
   $A*$B
)

Another expression can reference $A and $B to return 100.

Code Block
do(
   $c = 10,
   $A*$B*$C
)


$-variables are useful in the following scenarios.

...

:

  • 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.
    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.
  • ForEach loops (see the function)
  • Look up pipe use.
  • Really complicated expressions, where I want in complex expressions, to break up the use of multiple consecutive functions into separate lines. In this case, so I 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 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.

...

ExpressionResult
"Hello" + 3"Hello3"
"4" + 3"43"

Multiline

...

Statements and $-variables
Anchor
dollarVar
dollarVar

...


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.

ExpressionResult
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:

ExpressionResult
if ( in.customerName == "Smith", 45 , // else 36 )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:

...