Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Import Macro Repair


Insert excerpt
_Banners
_Banners
namephixScript
nopaneltrue

This page is for data modellers and application designers who need to reuse segments of scripts or expressions in multiple places.

Overview

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

  1. In the PhixFlow repository, add a new Macro item and name it.
  2. Add minimum and maximum parameters.
  3. Copy in the expression you want to reuse.
  4. To make an expression reusable in different contexts, change all references to named items to arguments, such as , $args[1]
  5. To use the macro in an expression, specify: macro_name(argument_name).
panel
borderColor#7da054
titleColorwhite
titleBGColor#7da054
borderStylesolid
titleSections on this page

Table of Contents
maxLevel3
indent12px
stylenone

For example, we want to reuse an expression:

if( out.AppleHarvestDate < 1, 1, 0)

Create a macro called isGreaterThanOne that contains the expression:

if($args[1] > 1, 1, 0)

To use the macro, replacing $arg[1] with the pipe and attribute name _out.AppleHarvestDate:

isGreaterThanOne(_out.AppleHarvestDate)

See also: 

For information about writing expressions and PhixScripts, see the Expressions and PhixScripts topic.

Macro 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.

Expression

FieldDescription
ExpressionEnter the expression that evaluates to a value based on the input parameters.

Example

Thie following 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 that an expression can be entered. For example, by entering 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
    )
  )
)


See also:

Filter by label (Content by label)
showLabelsfalse
max20
showSpacefalse
sorttitle
cqllabel = "macro" and space = currentSpace ( )



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