Versions Compared

Key

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

...

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:


Expression
Result

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:

...