Versions Compared

Key

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

Overview

Expressions contain brackets that contain set of arguments. The arguments are separated by commas. Expressions can also include:

  • PhixFlow Internal Variables
  • Functions
  • Regular Expressions
  • Escape Characters
  • User-defined variables, called $-variables; see Using Variables.

    Insert excerpt
    _Banners
    _Banners
    namephixScript
    nopaneltrue

    Parameter

    Overview

    This page explains the basics of writing expressions and scripts in the dynamic fields in PhixFlow . The instructions assume you are configuring a Stream Attribute, unless otherwise stated. Itproperty tabs.  It's also useful to know the style conventions recommeded recommended for expressions; see Expression Style.

    The elements you can use in an expression include:

    • a comment that provides documentation about what the expression does. PhixFlow ignores comments.
    • a literal value, for example a number or string
    • a variable; see Using Variables. This can be:
      • either a pre-defined internal variable
      • or your own user-defined $-variable.
    • a special string that matches a pattern in a string or array; see Regular Expressions
    • another expression
    • Function, which has a comma-separated list of arguments, enclosed in brackets.
      For example: dateGet(date,dateField)
    Tip

    The internal variables that you can use in an expression depend on the context. When you are writing an expression, always check the relevant help page. This will have information about what which internal variables your expression can include.

    Assigning a Literal Value to a Field

    The most basic expression simply assigns a constant value to the field.

    ExpressionAssigns valueData type33integer3.23.2floating point"Hello""Hello"string
    Panel
    borderColor#7da054
    titleColorwhite
    titleBGColor#7da054
    borderStylesolid
    titleSections on this page

    Table of Contents
    maxLevel3
    indent12px
    stylenone

    Tip

    To assign a string, it must be enclosed in:

    • either single quotes: 'Hello'
    • or double quotes: "Hello"

    Adding Comments

    It is always a good idea to add comments to document your expression. Comments help anyone who needs to modify the expression in the future.

    There are two ways to tell PhixFlow that a line is a comment, and can be ignored.

    NotationUse for
    //

     short comments up to 1 line

    /* <comment> */multi-line comments

    For some examples of using comments, plus other style tips for expressions, see Expression Style.

    Literal Values and Data Types

    Data Types 
    Anchor
    paramTypes
    paramTypes

    When writing expressions, it is important to consider the type of the result. For example,

    you can

    it is possible write an expression to return the integer 3

    but have defined

    for an attribute with the type

    of the stream attribute to be a

    string.

    If there is

    However, this has a mis-match between data types

    , when the expression is evaluated, PhixFlow stops evaluating the expression and

    . When PhixFlow evaluates an expression that contains a data-type mismatch, processing stops and PhixFlow reports an error.

    The full list of data types handled by PhixFlow is shown in the following table. 

    Data TypeDescriptionSee
    Array
    A list
     An object that contains an ordered list of values, e.g. [1,2,3]
    . For details about what other values arrays can hold and Array handling in general see . For details about date manipulation functions go to
    Date Functions
    DatetimeA date and time
    . For details about date manipulation functions go to Date FunctionsAssigning Values to Variables Anchordollarvar-introdollarvar-intro

    In PhixFlow, you can create your own variables using a $ symbol, for example $variableName; see Using Variables.

    Insert excerptUsing VariablesUsing Variablesnopaneltrue
    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 ""Text Expressions and Escape Characters
    BooleanA logical value of either true or false.
    Any non-null, non-zero value is treated as true

    Regular Expression
    Regular Expressions allow string patterns to be expressed; see Regular Expressions.
    Special character sequences that match a string pattern

    Regular Expressions

    Assigning a Literal Value

    The most basic expression simply assigns a constant value to the field.

    ExpressionAssigns valueData type
    33integer
    3.23.2floating point
    "Hello""Hello"string


    Tip

    To assign a string, it must be enclosed in:

    • either single quotes: 'Hello'
    • or double quotes: "Hello"

    When working with strings, be aware that some characters have special meaning. You need to use an escape character for strings that include special characters; see Text Expressions and Escape Characters.

    Referencing Attribute Names

    Assigning Values From a Pipe 
    Anchor
    pipe
    pipe

    Stream attribute

    Attribute expressions are commonly used 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. For example: 

      in.accountRef

    This expression causes PhixFlow to look at the pipe named "in" and return the value in the field called "accountRef".

    Tip

    This expression can return multiple values; see Arrays and Record Sets.

    Calculating an Attribute Name Using a $-variable

    In PhixFlow, you can create your own variables using a $ symbol, for example $variableName; see Using Variables.

    If the name of the attribute whose value you want has to be calculated based on other factors, you can assign the attribute name to a $-variable. You then use the variable instead of the attribute name itself. For example:

      in.$attrName

    Handling Invalid Characters in Attribute Names

    There are two options for handling an attribute name that contains invalid characters.

    • Either assign that name to a variable and use the variable instead of the actual attribute.
    • Or enclose the name in quotes, for example:  in.'account-ref'.

    Numbers and Strings

    Mathematical Operators (+, -, *, /)

    Several values can be combined using the usual basic mathematical operators. For example when in.numProducts has the value 9:

    ExpressionResult
    in.numProducts + 312
    in.numProducts - 36
    in.numProducts * 327
    in.numProducts / 33

    The usual calculation precedences apply, so * and / operations are carried out before + and -. When the mathematical statements involve multiple calculations, use brackets ( ) to force the correct processing order.

    ExpressionResult
    3 * 3 + 312
    3 * (3 + 3)18

    String Concatenation (+)

    The + operator also serves as the string concatenation operator. This means you can use + to  join strings together. For example if in.customerName returns "Smith" and in.title returns "Mr":

    ExpressionResult
    "Hello" + " to " + "you""Hello to you"
    "Dear " + in.title+ " " in.customerName + "," +"Dear Mr Smith,"


    Note

    If you use + to concatenate a string and a number (integer or floating point), then PhixFlow treats the number as if it is a string. For example:

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

    Internal Variables

    Sometimes when youWhen you pass a a value that is passed between programs, subroutines or functions. Arguments are independent items, or variables, that contain data or codes.

    PhixFlow has a list of functions you can use in an expression.

    ExpressionInternal Variableif( _out.AppleHarvestDate <


     expression within an expression

    internal variable

    _out. tells PhixFlow that it has already "seen" the attribute AppleHarvestDate in this stream.

    You can refer to

    <pipe_name>.<attribute_name> and pipe names default to "in", so  in.AppleHarvestDate which signals that AppleHarvestDate is being sourced down a pipe going into the stream called 'in'. The internal variable preceding an attribute name should reflect where the attribute is being source from.

    There are many other internal variables, see Internal Variables.

    Regular Expressions - Regular expressions can be used to match patterns within strings or arrays as arguments within jep expressions, for example replaceAllreplaceFirst and matches. See Regexp ToDelete.

    Simple integers or strings. In the above case 1 and 0 are simple integers. They tell PhixFlow to return the number 1 if NumberOfApples > 1 and 0 if it is not. A string could be returned instead eg. if(_out.NumberOfApples > 1, 'True', 'False') would return the string True if NumberOfApples >1 and False if it is not. Note strings need to be wrapped in ' marks. 

    (To find the correct syntax for an expression - find it in the list below or search in confluence)

    If() Statements

    It is common to want to evaluate whether or not data meets a condition. To do this use an if() statement; see the if page.

    ExpressionResult

    if(_out.NumberOfApples > 1, 1, 0)

    tbcMultiline Statements and $-variables

    Functions, Arguments and $-Variables

    PhixFlow has a set of functions you can use in expressions. Functions have a set of comma-separated arguments, enclosed in backets, like this: name (arg1, arg2), where arg is an argument. Each function has a help page explaining it's syntax and what PhixFlow expects for each argument ; see Functions.

    $-Variables in the Do() Function
    Anchor
    dollarvar-intro
    dollarvar-intro

    Insert excerpt
    Using Variables
    Using Variables
    nopaneltrue

    True or False using the If() Function

    It is common to want to evaluate whether or not data meets a condition. To do this use the if() function in an expression. This function has 3 arguments.

    Code Block
    if(
        //argument 1 - the condition
       _out.AppleHarvestDate < _toDate('20210101'),
    
        //argument 2 - return this if true
        1,
    
        //argument 3 - return this if false
        0
    
    )
    toDate converts the string 20210101 into a date 01-01-2021)

    In this expression, the first argument is the condition, which is also an expression. This selects records that have a date before 1st January 2021. The remaining arguments are simple integers. For records that:

    • meet the condition, PhixFlow returns 1 to indicate true.
    • do not meet the condition, PhixFlow returns 0 to indicate false.

    Alternatively, the expression could return strings, which must be enclosed in quote marks.

    Code Block
    if(
       _out.AppleHarvestDate < _toDate('20210101'),
        "true",
        "false"
    )

    Multiline Statements
    Anchor
    dollarVar
    dollarVar

    When you are working with more complex expression, you may have several different statements to evaluate first. To group statements together, use the do() function.

    In multi-line statements, you usually need to assign the value of an expression to a $-variable, to use later in the expression. For example:

    ExpressionResult

    do (

        $name = in.customerName,

        $title = in.title,

        $salutation = "Dear",

        $result = $salutation + ' ' + $title + $name

    )

    "Dear Mr Smith"


    Note

    Statements in the do() function end in a comma, except the last one.

    The value of an expression that is used, is the value of

    PhixFlow uses the value from the last statement to be evaluated. In simple expressions, such as the example above, the last statement to be evaluated is the last line of the expression. However, in 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

    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.

    NotationUse for//

     short comments up to 1 line

    /* <comment> */multi-line comments

    For some examples using comments, plus other style tips for expressions, see Expression Style.

    See Also

    Expressions and Scripts topic page for links to more information.

    Expressions in Other Dynamic Fields

    In some cases, a dynamic field is expecting a form of code other than an expression. For example a database collector has a dynamic field where you can enter SQL statements. If you want to include an expression in this type of field, it needs to be enclosed in curly brackets. For example, the following SQL statement includes the expression in.key.

    Code Block
    select * from mytable where mykey = {in.key}


    Popup Help for Expressions

    When you are writing an expression, PhixFlow provides popup windows to help you. You can:

    • start to enter an expression. Select a string to display a popup with information about whether the string is valid.
    • start to enter a Function name. PhixFlow displays a list that you can scroll to find the function name you require.
          Image Added
    • Enter a function. Click into the brackets to see a summary of the function syntax.
      Click Learn More to see the full help page for the function.
          Image Added

    Live Search
    spaceKey@self
    additionalnone
    placeholderSearch all help pages
    typepage

    Panel
    borderColor#00374F
    titleColorwhite
    titleBGColor#00374F
    borderStylesolid
    titleSections on this page

    Table of Contents
    maxLevel3
    indent12px
    stylenone