Skip to Content
DataFormula & Conditions

Formula and Conditions

Formulas and Conditional Judgments

In addition to being used directly by actions and components, data can also be processed through formulas and conditional logic.

Formulas

Formulas are functions used to calculate or transform data. Momen provides a variety of formulas for operations on text, numbers, arrays, time, and more.

Type Conversion

NameDescriptionExample
TO_TEXTConverts integers, decimals, JSONB, etc., to textOriginal data: {"message": "Hello World!"}'{"message": "Hello World!"}'
TO_INTEGERConverts text or decimals to integersOriginal data: -3.1415926-3
TO_DECIMALConverts text to decimalsOriginal data: "-3.1415926"-3.1415926
TEXT_TO_DATETIMEConverts text to datetimeOriginal data: "2025-02-21 14:36"2025-02-21T14:36:00.000+08:00
COMBINE_DATE_AND_TIMECombines date and time into datetimeDate: 2024-01-08, Time: 13:38:00.000+08:002024-01-08T13:38:00.000+08:00
EXTRACT_DATE_OR_TIMEExtracts date or time from datetime (timestamp)Datetime: 2024-01-08 13:38:00.000+08:00, Extract: Date → 2024-01-08

Text Processing

NameDescriptionExample
STRING_LENReturns the length of the text. All characters (including Chinese, letters, numbers, symbols) count as one.Text: "Hello World!"12
REPLACE_PARTReplaces part of the text with new text based on the specified position (first character is 0) and number of characters.Text: "Hello World!", Start: 1, Length: 4, New text: "ola""Hola World!"
REPLACE_TEXTFinds the specified text and replaces it with new text, based on the number of occurrences.Text: "Hello World!", Old: "o", New: "", Count: 1"Hell World"
FINDReturns the position of the first occurrence of the specified text. Returns -1 if not found.Text: "Hello World!", Find: "o"4
CONTAINChecks if the specified text exists, returns true or false.Text: "Hello World!", Find: "ello"true
SUBSTRINGExtracts a substring. Includes the start position but not the end; first character is 0.Text: "Hello World!", Start: 0, End: 5"Hello"
LEFTReturns a specified number of characters from the start of the text.Text: "Hello World!", Count: 5"Hello"
RIGHTReturns a specified number of characters from the end of the text.Text: "Hello World!", Count: 5"World"
LOWERConverts all letters in the text to lowercase.Text: "Hello World!""hello world!"
UPPERConverts all letters in the text to uppercase.Text: "Hello World!""HELLO WORLD!"
RANDOM_STRINGGenerates random text. (Random characters are generated on the frontend and are not recommended for secure scenarios such as coupon codes.)Min length: 5, Max length: 10, Lowercase: true, Uppercase: true, Numbers: true"seXr3aoRD"
SPLITSplits the text into an array using the specified separator.Text: "2024/01/08", Separator: "/"["2024", "01", "08"]
ENCODE_URLConverts text string to URL standard formatText: "https://docs.momen.app/data/formula/""https%3A%2F%2Fdocs.momen.app%2Fdata%2Fformula%2F"
DECODE_URLDecodes a URL encoded by ENCODE_URL functionText: "https%3A%2F%2Fdocs.momen.app%2Fdata%2Fformula%2F""https://docs.momen.app/data/formula/"
UUIDRandomly generates a string-type unique identifierNone → "550e8400-e29b-41d4-a716-446655440000"
TEXT_REPEATRepeats text a specified number of timesText: "Yes", Count: 3"YesYesYes"
TRIMRemoves spaces from the beginning and end of textText: " dadada ""dadada"
REGEX_EXTRACTExtracts the first text segment that matches the regexText: "Phone number is 13940983244", Regex: \d{11}"13940983244"
REGEX_EXTRACTALLReturns all text segments that match the regexText: "Phone: 13940983244 and 13234322452", Regex: \d{11}["13940983244","13234322452"]
REGEX_MATCHDetermines if text contains content that matches the regexText: "13812345678", Regex: ^\d{11}$true
REGEX_REPLACEReplaces parts of text that match the regexSource text: "Phone number is 13812345678", Regex: \d{11}, Replace: "***********""Phone number is ***********"

Mathematical Operations

NameDescriptionExample
+Addition5 + 1015
-Subtraction5 - 10-5
*Multiplication5 * 1050
/Division5 / 100.5
%Remainder after division, same sign as dividend-5 % 10-5
MINReturns the minimum value5, 105
MAXReturns the maximum value5, 1010
ROUND_UPRounds up to the nearest integer3.54
ROUND_DOWNRounds down to the nearest integer-3.5-4
INTRounds to the nearest integer-3.5-3
ABSReturns the absolute value-3.53.5
RANDOM_NUMBERReturns a random integer between specified numbers (not recommended for secure scenarios)Min: 1, Max: 106
POWERExponentiationBase: 2, Exponent: 38
DECIMAL_FORMATDecimal formatting (returns text if “Remove all trailing zeros” is selected)3.1415926, Precision: 2, Remove trailing: true3.14
LOGReturns the logarithm of a number with specified baseTrue number: 8, Base: 23

Array Processing

NameDescriptionExample
GET_ITEMRetrieves an item from an array (index starts from 0)["2024", "01", "08"], Index: 1"01"
ARRAY_TO_ITEMRetrieves an item from an array (deprecated, use GET_ITEM)["2024", "01", "08"], Index: 1"01"
ARR_LENGets the length of the array["2024", "01", "08"]3
FIRSTReturns the first item of the array["2024", "01", "08"]"2024"
LASTReturns the last item of the array["2024", "01", "08"]"08"
RANDOM_ITEMReturns a random item from the array["2024", "01", "08"]"01"
SLICEExtracts a section of the array["2024", "01", "08"], Start: 1, Count: 2["01", "08"]
JOINJoins an array of text into a string["2024", "01", "08"], Separator: "-""2024-01-08"
INDEX_OFReturns the index of the first occurrence of the specified item["2024", "01", "08"], Item: "08"2
SEQUENCEGenerates a number sequence within the specified range. Returns empty array if end number is less than or equal to start number.Start: 1, End: 10, Step: 2[1,3,5,7,9]
COALESCEReturns the first “non-null” item in the array from left to rightArray: [null,1,3,2]1
ARRAY_MAXReturns the maximum item value in the arrayArray: [1,2,3]3
ARRAY_MINReturns the minimum item value in the arrayArray: [1,2,3]1
ARRAY_SUMSums the values of items in the arrayArray: [1,2,3]6
ARRAY_AVERAGEReturns the average value of items in the arrayArray: [1,2,3]2
ARRAY_CONCATMerges two arrays into one arrayArray1: [1,2,3,4,5], Array2: [2,3,4][1,2,3,4,5,2,3,4]
UNIQUERemoves duplicate items from the arrayArray: [1,2,5,4,5,2,3,4][1,2,5,4,3]

Time Operations

NameDescriptionExample
GET_DATE_TIMEGets a point in timeYear: 2024, Month: 1, Day: 8, Hour: 13, Minute: 14, Second: 02024-01-08T13:14:00.000+08:00
DELTAAdds or subtracts timeTime: 13:38:00.000+08:00, Add 1 hour 12 min14:50:00.000+08:00
DURATIONCalculates the interval between two points in timeStart: 2019-12-01, End: 2024-01-08, Unit: Year5
EXTRACTRetrieves a specified part of the time. For day of week, outputs integers 0-6, where 0 represents SundayTime: 13:38:00.000+08:00, Unit: Hour13
TO_DATETIMEConverts date and time into DateTime (timestamp)Date: 2024-01-08, Time: 13:38:00.000+08:002024-01-08T13:38:00.000+08:00
TO_DATE_TIMERetrieves the date or time from a DateTime (timestamp)DateTime: 2024-01-08 13:38:00.000+08:00, Extract: Date2024-01-08

Geographical Location

NameDescriptionExample
DISTANCECalculates the distance between two locations (meters, kilometers, or miles)[120.2934,30.3150], [120.2934,31.3150], km866
GET_VALUE_FROM_GEO_POINTRetrieves longitude or latitude from a geo point (latitude and longitude)[120.2934,30.3150], Type: Latitude30.3150

JSON Processing Methods

NameDescriptionExample
JSON_EXTRACT_PATHRetrieves data from JSON{"data": {"foo": "bar"}}, Path: data.foo"bar"

Conditions

Logical operations on data are used in Conditional View, Conditional Data, and conditional branches of Actionflow. For detailed usage, see the relevant documentation.

Formula and condition usage example

Last updated on