Macro functions and editor
Macros transform text, calculate values, format dates, and evaluate saved conditions. Use the Macro editor in fields that provide a function control, including app parameters and content editors.
The editor lets you build an expression and inspect its Preview before returning the expression to the original field.
Before you start
Configure your project's data schema before using Preview. Preview requires a saved, nonempty data schema, even when the expression contains only literal text. If it is missing, Flowize displays Please set up your data schema before testing.
Preview uses the project's saved data schema and, when configured, its static data. Values available during an actual flow execution can differ from these preview values.
Create a macro
- Open a field with the function icon, or select Macro Editor in a content source editor.
- Enter or edit the text in the Macro editor. The editor loads the original field's text; supported source editors can load the selected text instead.
- Select the text to transform. For example, select
Flowizeand choosestrtoupperto wrap it in an uppercase macro. To insert an expression without replacing text, place the cursor where it should go. - Expand a category under Macros, or use Search to find a function. Enter two or more letters to filter the list; use the clear control to restore it.
- Select the function. Review the inserted expression and replace parameter placeholders with the values you need.
- Check Preview. For nonempty text, it updates after you choose a function or pause while typing. A loading indicator appears while Flowize calculates the result.
- Select Accept to return the expression to the original field and close the editor.
- Save or apply the changes in the surrounding app, flow, or content editor.
Accept inserts the expression shown in the editing area, including its macro tags. It does not replace the expression with the preview result. Closing the window without selecting Accept leaves the original field unchanged.
Use Undo and Redo to move through the editor's expression and preview history. This history resets when you open the editor again. Help opens the macro reference.
Macro syntax
Wrap an expression in [MACRO] and [#MACRO]. Put the function's parameters inside parentheses and separate multiple parameters with |:
[MACRO]function_name(value|parameter2)[#MACRO]
For example:
[MACRO]str_replace(red|blue|red folder)[#MACRO]
This returns blue folder. Parameter order matters: str_replace takes the search text, replacement text, and input text in that order.
You can place more than one macro in a text field. Text outside the macro tags remains part of the output:
Total: [MACRO]sum(10|20|5)[#MACRO]
This returns Total: 35.
Use variables
Use a variable as a parameter when that variable exists in your project. For example, if your data schema defines @data.client.name@:
[MACRO]strtoupper(@data.client.name@)[#MACRO]
Flowize replaces supported variables before evaluating the function. The result depends on the variable's available value.
Nest functions
Functions can be nested inside one pair of macro tags. Flowize evaluates the innermost function first:
[MACRO]strtoupper(trim( Flowize ))[#MACRO]
This removes the surrounding spaces, then returns FLOWIZE.
Read the function reference
The tables below list parameters in their input order. Parameters marked optional can be omitted when they are at the end of the expression. To supply a later parameter while leaving an earlier one empty, keep its position with consecutive | separators.
For example, special_random requires three positions even when its character list is empty:
[MACRO]special_random(|6|NUMBER)[#MACRO]
The inserted templates include examples and placeholders. Replace placeholders such as needle, precision, and num2 before accepting the expression.
Many functions split their input at every |. If your input text contains this character, check the result in Preview; surrounding the text with quotes does not generally protect it from parameter splitting.
Function categories
The Macros list groups functions into Condition, Compression, Date, Encoding, Encryption, HTML, Json, Math, and String. The following reference covers the functions listed in those categories.
Condition
| Function | Parameters | Result |
|---|---|---|
if | Saved condition name, positive statement, negative statement (optional). | Returns the positive statement when the condition is true. Otherwise, returns the negative statement, or empty text when it is omitted. |
Create the condition before referring to it by name. For example, if a condition named Eligible exists:
[MACRO]if(Eligible|Eligible customer|Other customer)[#MACRO]
Compression
| Function | Parameters | Result |
|---|---|---|
deflate | String, compression level (optional). | DEFLATE-compressed data encoded as Base64 text. |
compress | String, compression level (optional). | ZLIB-compressed data encoded as Base64 text. |
inflate | Base64 text produced by deflate. | Decompressed text. |
uncompress | Base64 text produced by compress. | Decompressed text. |
Use a compression level from 0 to 9. The editor inserts 6; omitting the level uses the compression library's default. Match deflate with inflate, and compress with uncompress.
Date
| Function | Parameters | Result |
|---|---|---|
date | Output format, timestamp (optional). | Formats the current time, or the supplied timestamp. |
date_format | Date/time, output format (optional), output timezone (optional). | Formats a date/time, applying the supplied recognized timezone. The default output format is Y-m-d H:i:s. |
date_format_lang | Date/time, input format, input timezone, language, output Unicode format, output timezone. | Formats a date/time using the selected language and output timezone. |
date_add | Date/time, interval, output format (optional), output timezone (optional). | Adds the interval and returns the formatted date/time. The default output format is Y-m-d H:i:s. |
date_sub | Date/time, interval, output format (optional), output timezone (optional). | Subtracts the interval and returns the formatted date/time. The default output format is Y-m-d H:i:s. |
date_to_timestamp | Date text, Unicode input format, language, timezone. | Parses a localized date and returns its timestamp. |
date_diff | First date/time, second date/time, difference format (optional). | Returns the difference in the requested format. The default is %r%a days. |
For date, the first parameter is the output format, although the list labels it datetime. The inserted expression is:
[MACRO]date(Y-m-d H:i:s)[#MACRO]
date_format_lang uses different patterns for its input and output. For example, the editor inserts Y-m-d H:i:s for the input format and MMMM dd, y HH:mm:ss for the output Unicode format. Its timezone parameters describe the input and output separately. date_to_timestamp also uses a Unicode format for its input.
The date-add and date-subtract templates insert the interval P1D. Review the inserted timezone and format before using the expression.
Encoding
| Function | Parameters | Result |
|---|---|---|
base64_encode | String. | Base64-encoded text. |
base64_decode | Base64 text. | Decoded data. |
json_xml | JSON string. | XML generated from a decoded JSON array or object, with a root element. |
xml_json | XML string. | JSON text representing the XML content. |
mb_convert_encoding | String, target encoding, source encoding (optional). | Text converted to the target character encoding. |
get_public_url | File Manager path, custom domain (optional). | A public URL for the path, using the configured domain when the custom domain is omitted. |
For get_public_url, supply a File Manager path. Generating the URL does not verify that the file exists or can be retrieved.
Encryption
The Encryption category includes hash and checksum functions.
| Function | Parameters | Result |
|---|---|---|
sha1 | String. | SHA-1 hash. |
md5 | String. | MD5 hash. |
crc32 | String. | CRC32 checksum. |
hash_hmac | Algorithm, message, key, raw output (optional). | HMAC hash. Output is hexadecimal by default; the fourth parameter true requests raw binary output. |
crypt | The editor displays string and salt. | The parameter hint and evaluator differ |
HTML
| Function | Parameters | Result |
|---|---|---|
htmlentities | String. | Text with applicable characters converted to HTML entities. |
html_entity_decode | String. | Text with HTML entities decoded. |
htmlspecialchars | String. | Text with special HTML characters converted to entities. |
htmlspecialchars_decode | String. | Text with special HTML entities decoded. |
urlencode | String. | URL-encoded text. |
urldecode | String. | URL-decoded text. |
strip_tags | String, allowed tags (optional). | Text with HTML tags removed, retaining supplied allowed tags. Also listed under String. |
nl2br | String, XHTML output (optional). | Text with HTML line breaks inserted for newlines. |
Json
| Function | Parameters | Result |
|---|---|---|
json_encode | Value, flag (optional). | JSON text when the value is an array or object, or decodes to one. Use UNESCAPED_UNICODE to keep Unicode characters unescaped. |
json_decode | JSON string, decode as array (optional). | A decoded JSON value. The second parameter controls whether JSON objects become arrays (true or 1) or objects (false or 0, the default). |
json_path | JSON string, JSONPath beginning with $. | The matched value when there is one match, or the collection of matches otherwise. |
When an expression returns an array, object, number, or Boolean, Flowize converts that result to JSON text for insertion into the surrounding text.
For example:
[MACRO]json_path({"customer":{"name":"Ada"}}|$.customer.name)[#MACRO]
This returns Ada.
Math
| Function | Parameters | Result |
|---|---|---|
sum | Numbers separated by |. | Sum of the numbers. |
subtract | First number, one or more further numbers. | Subtracts each further number from the running result. |
multiply | Numbers separated by |. | Product of the numbers. |
division | First number, one or more divisors. | Divides the running result by each divisor. A zero divisor sets the running result to 0. |
opposite | Number. | The number with its sign reversed. |
round | Number, precision. | Number rounded to the supplied precision. |
number_format | Number; or number, decimals, decimal separator, thousands separator. | Formatted number. With only the number, it uses two decimal places. Supply all four positions to customize formatting. |
hex2bin | Hexadecimal string. | Binary data. Input must contain hexadecimal characters and have an even length. |
special_random | Character list, length, type. | Random text using the selected character set. Also listed under String. |
eval_spreadsheet_formula | Spreadsheet formula. | Calculated formula result. The leading = is optional. |
Although the Math list labels special_random with only length and type, use all three positions. Leave the character-list position empty for a predefined set, as in special_random(|6|NUMBER).
For example:
[MACRO]number_format(1234.5|2|.|,)[#MACRO]
This returns 1,234.50.
String
| Function | Parameters | Result |
|---|---|---|
trim | String, character mask (optional). | Text with whitespace, or the selected characters, removed from both ends. |
ltrim | String, character mask (optional). | Text with whitespace, or the selected characters, removed from the beginning. |
rtrim | String, character mask (optional). | Text with whitespace, or the selected characters, removed from the end. |
strtolower | String. | Lowercase text. |
strtoupper | String. | Uppercase text. |
lcfirst | String. | Text with its first character lowercase. |
ucfirst | String. | Text with its first character uppercase. |
ucwords | String, delimiters (optional). | Text with the first character of each word uppercase. |
strlen | String. | Character count. |
substr | String, start position, length (optional). | The selected part of the text. |
strpos | String, search text, offset (optional). | Position of the first match. Returns 0 when there is no match and also when the match starts at position 0. |
stripos | String, search text, offset (optional). | The same position result with a case-insensitive search. |
str_pad | String, target length, padding text (optional), padding type (optional). | Padded text. The defaults are spaces and STR_PAD_RIGHT; STR_PAD_LEFT and STR_PAD_BOTH are also accepted. |
str_repeat | String, repeat count. | Repeated text. |
str_replace | Search text, replacement text, input string. | Text with matching substrings replaced. |
str_shuffle | String. | Randomly reordered text. |
remove_break_lines | String. | Text with carriage returns and newlines removed. |
explode | Delimiter, string. | An array of text parts. With a single parameter, it splits that text at commas. |
is_array | Value. | 1 for an array or JSON array; otherwise 0. |
is_object | Value. | 1 for an object or JSON object; otherwise 0. |
is_numeric | Value. | 1 for a numeric value; otherwise 0. |
is_bool | Value. | 1 for the text true or false; 0 for 1 or 0. Other values use Boolean validation. |
is_string | Value. | 1 for a string, excluding numeric values, empty values, [], {}, true, and false; otherwise 0. |
str_to_object | JSON text. | A decoded value. Arrays and objects appear as JSON text in the final output. |
similar_text | First string, second string. | Similarity percentage. |
levenshtein | First string, second string. | Edit distance between nonempty strings. Returns -1 when either string exceeds 255 characters. |
special_random | Character list, length, type. | Random text; see the character sets below. |
strip_tags is also listed in this category; its parameters and result are described under HTML.
For special_random, use ALL, LOWERCASE, UPPERCASE, NUMBER, or SYMBOL for predefined character sets. CUSTOM uses the characters in the first parameter. LIST selects entries from a list separated by #. Lengths above 2048 are capped at 2048 selections.
For example:
[MACRO]special_random(abc|6|CUSTOM)[#MACRO]
This returns six characters chosen from a, b, and c. The value changes when the macro is evaluated again.
String contains
str_contains takes an input string and search text. It returns true when the input contains the search text, or false otherwise.
[MACRO]str_contains(Flowize|Flow)[#MACRO]
This returns true.
String starts with
str_starts_with takes an input string and search text. It returns true when the input starts with the search text, or false otherwise.
[MACRO]str_starts_with(Flowize|Flow)[#MACRO]
This returns true.
String ends with
str_ends_with takes an input string and search text. It returns true when the input ends with the search text, or false otherwise.
[MACRO]str_ends_with(Flowize|ize)[#MACRO]
This returns true.
Preg replace
preg_replace takes a regular expression pattern, replacement text, and input string. It returns the text with matches replaced. Include the pattern delimiters in the first parameter.
[MACRO]preg_replace(/[0-9]+/|#|Order 123)[#MACRO]
This returns Order #.
Check the result
Replace all parameter placeholders and compare Preview with the result you expect. Check the order and number of parameters, variable values, date formats, timezones, and matching macro tags.
Preview is a calculation aid. Some invalid inputs produce empty text or leave an input value unchanged instead of displaying an error. An empty or unchanged result therefore does not confirm that the expression is valid.
Clearing the editing area does not trigger a new calculation, so Preview can still show the previous result.
Random functions and functions that use the current time are evaluated again when the expression is processed. Their execution results can differ from Preview.
Was this article helpful?