Skip to main content

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​

  1. Open a field with the function icon, or select Macro Editor in a content source editor.
  2. 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.
  3. Select the text to transform. For example, select Flowize and choose strtoupper to wrap it in an uppercase macro. To insert an expression without replacing text, place the cursor where it should go.
  4. 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.
  5. Select the function. Review the inserted expression and replace parameter placeholders with the values you need.
  6. 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.
  7. Select Accept to return the expression to the original field and close the editor.
  8. 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​

FunctionParametersResult
ifSaved 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​

FunctionParametersResult
deflateString, compression level (optional).DEFLATE-compressed data encoded as Base64 text.
compressString, compression level (optional).ZLIB-compressed data encoded as Base64 text.
inflateBase64 text produced by deflate.Decompressed text.
uncompressBase64 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​

FunctionParametersResult
dateOutput format, timestamp (optional).Formats the current time, or the supplied timestamp.
date_formatDate/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_langDate/time, input format, input timezone, language, output Unicode format, output timezone.Formats a date/time using the selected language and output timezone.
date_addDate/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_subDate/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_timestampDate text, Unicode input format, language, timezone.Parses a localized date and returns its timestamp.
date_diffFirst 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​

FunctionParametersResult
base64_encodeString.Base64-encoded text.
base64_decodeBase64 text.Decoded data.
json_xmlJSON string.XML generated from a decoded JSON array or object, with a root element.
xml_jsonXML string.JSON text representing the XML content.
mb_convert_encodingString, target encoding, source encoding (optional).Text converted to the target character encoding.
get_public_urlFile 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.

FunctionParametersResult
sha1String.SHA-1 hash.
md5String.MD5 hash.
crc32String.CRC32 checksum.
hash_hmacAlgorithm, message, key, raw output (optional).HMAC hash. Output is hexadecimal by default; the fourth parameter true requests raw binary output.
cryptThe editor displays string and salt.The parameter hint and evaluator differ

HTML​

FunctionParametersResult
htmlentitiesString.Text with applicable characters converted to HTML entities.
html_entity_decodeString.Text with HTML entities decoded.
htmlspecialcharsString.Text with special HTML characters converted to entities.
htmlspecialchars_decodeString.Text with special HTML entities decoded.
urlencodeString.URL-encoded text.
urldecodeString.URL-decoded text.
strip_tagsString, allowed tags (optional).Text with HTML tags removed, retaining supplied allowed tags. Also listed under String.
nl2brString, XHTML output (optional).Text with HTML line breaks inserted for newlines.

Json​

FunctionParametersResult
json_encodeValue, 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_decodeJSON 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_pathJSON 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​

FunctionParametersResult
sumNumbers separated by |.Sum of the numbers.
subtractFirst number, one or more further numbers.Subtracts each further number from the running result.
multiplyNumbers separated by |.Product of the numbers.
divisionFirst number, one or more divisors.Divides the running result by each divisor. A zero divisor sets the running result to 0.
oppositeNumber.The number with its sign reversed.
roundNumber, precision.Number rounded to the supplied precision.
number_formatNumber; 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.
hex2binHexadecimal string.Binary data. Input must contain hexadecimal characters and have an even length.
special_randomCharacter list, length, type.Random text using the selected character set. Also listed under String.
eval_spreadsheet_formulaSpreadsheet 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​

FunctionParametersResult
trimString, character mask (optional).Text with whitespace, or the selected characters, removed from both ends.
ltrimString, character mask (optional).Text with whitespace, or the selected characters, removed from the beginning.
rtrimString, character mask (optional).Text with whitespace, or the selected characters, removed from the end.
strtolowerString.Lowercase text.
strtoupperString.Uppercase text.
lcfirstString.Text with its first character lowercase.
ucfirstString.Text with its first character uppercase.
ucwordsString, delimiters (optional).Text with the first character of each word uppercase.
strlenString.Character count.
substrString, start position, length (optional).The selected part of the text.
strposString, 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.
striposString, search text, offset (optional).The same position result with a case-insensitive search.
str_padString, 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_repeatString, repeat count.Repeated text.
str_replaceSearch text, replacement text, input string.Text with matching substrings replaced.
str_shuffleString.Randomly reordered text.
remove_break_linesString.Text with carriage returns and newlines removed.
explodeDelimiter, string.An array of text parts. With a single parameter, it splits that text at commas.
is_arrayValue.1 for an array or JSON array; otherwise 0.
is_objectValue.1 for an object or JSON object; otherwise 0.
is_numericValue.1 for a numeric value; otherwise 0.
is_boolValue.1 for the text true or false; 0 for 1 or 0. Other values use Boolean validation.
is_stringValue.1 for a string, excluding numeric values, empty values, [], {}, true, and false; otherwise 0.
str_to_objectJSON text.A decoded value. Arrays and objects appear as JSON text in the final output.
similar_textFirst string, second string.Similarity percentage.
levenshteinFirst string, second string.Edit distance between nonempty strings. Returns -1 when either string exceeds 255 characters.
special_randomCharacter 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?