Flow.apex

  • Docs
  • Tutorials
Docs Menu
  • Flows
  • Flow Methods
    • Creation Methods
    • Function Methods
    • Block Methods
    • Static Methods
  • FlowScript

FlowScript Guide

FlowScript

What is FlowScript?

FlowScript is a small scripting language packaged with Flow.apex. FlowScript is used to convert javascript-like scripts into Flow.apex code.

How does FlowScript work?

FlowScript bascially is just an interpreter from a more readable script to Flow.apex code.

Flow f = new Flow()
    .var('n = n + 1');

This embedded FlowScript is then translated into this:

Flow f = new Flow()
    .var('n', Flow.s('n + 1'));

Flow.s(String) is a tool used to convert Strings into deferred Flow.apex code invocations. It eventually translates the script into:

Flow f = new Flow()
    .var('n', Flow.call(R.add.apply(1), Flow.getVar('n')));

The purpose of FlowScript is to make the code easier to read, and fundamentally it does not change the code logic.

The interpretation of FlowScript happens only once when the Flow is created. Therefore further performance penalty is avoided.

FlowScript Evaluation

We can evaluate FlowScript independently from Flow.apex.

Object value = Flow.eval('add(a, b)', new Map{
    'a' => 1,
    'b' => 2
});

FlowScript Syntax

FlowScript follows most of JavaScript syntax, with these exceptions:

  • Functions instead of methods FlowScript supports only functions like add(1, 2), not a.add(1, 2).

  • Reference of thisIn FlowScript, this always refers to the current Flow object.

Supported Unary Operators

OperatorDescription
-Negate the number
!Negate the boolean
++(prefixed)Increment the number
--(prefixed)Decrement the number

Supported Binary Operators

OperatorDescription
==Equals
!=Not Equals
<Less than
>Greater than
<=Less than or equals
>=Greater than or equals
+Add
-Minus
*Multiply
/Divide
%Modulo

Supported Logical Operators

OperatorDescription
!Negate the boolean
&&Logical And
\\Logical Or

Supported Ternary Operators

OperatorDescription
? :If ... then ... else ...

Array Literal

Flow f = new Flow()
    .var('a = ["a", "b"]');

Map Literal

Flow f = new Flow()
    .var('a = { "name" => "value" }');

Contribute on Github! Edit this section.