Versions Compared

Key

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

Overview

Sometimes we might want to write our own expressions that can be used time and again. To do this we can write a macro.

To make an expression reusable in different contexts, you need to replace any use an argument, $args[1], to replace references to named items, such as attributes with arguments, such as $args[1], $args[2].  To .

To use the macro in an expression, specify:

...

isGreaterThanOne(_out.AppleHarvestDate)

See also: Expressions , and Scripts and Macros


Properties

Insert excerpt
_standard_settings
_standard_settings
nopaneltrue

Basic Settings

FieldDescription
NameThe name of the macro. This name is also how the macro will be invoked (called) from elsewhere in PhixFlow
Minimum ParametersThe minumum number of parameters that must be passed to the macro when it is invoked.
Maximum ParametersThe maximum number of parameters that may be passed to the macro when it is invoked.

...

This sample macro is called padCost. It takes 1 parameter - a numeric value. It checks to see if the numeric value is missing a 0 before a decimal point. If so, it adds the 0 and returns the string. It can be called anywhere in phixflow PhixFlow that an expression can be entered (, for example) , with :

padCost(".977")

Code Block
do(
  $val = $args[1],
  if( startsWith($val, "."),
    // if the cost is positive, add a zero onto the beginning
    "0" + $val,
    // ELSE
    if( startsWith($val, "-."),
      //if the cost is negative, replace the -. with a -0.
      "-0." + substring($val,3),
      //ELSE
      $val
    )
  )
)

...