Data Types

Karl Falconer ·

Every value in BGL has a type. The four core types are text, number, date, and boolean. Most of the time the type is implicit from the value — "UPS" is text, 100.0 is a number — and you don’t need to think about it. When you do need to think about it, this article is the reference.

The four types

Type Examples
Text "UPS", "premium", "order #1234"
Number 0, 1, 1.5, -42, 100.0
Date @now, @today, @2024-01-15, @T10:30:00
Boolean true, false

There’s also a special value, blank — meaning no value. See Null Handling.

Text

Always double-quoted. Single quotes don’t make a string in BGL.

"UPS"
"This is a string with \"quoted\" text"
""        # the empty string

Concatenate with &:

"Hello, " & order.shipping_address.first_name & "!"

For matching, slicing, and replacing, see Strings and Regex.

Number

0
1
1.5
-42
100.0

There’s no integer/float distinction at the syntax level — 1 and 1.0 both work. Operators: +, -, *, /, % (modulo), // (integer division). Standard arithmetic precedence; use parentheses for clarity.

Date

Date literals always start with @:

Form Example Meaning
Named @now, @today, @tomorrow Current/relative time
ISO @2024-01-15T10:30:00+00:00 Full timestamp
Time only @T10:30:00, @10:30:00 Time of day
Weekday @monday through @sunday A day of the week
Month @january through @december A month
Year @2024 A year

For arithmetic and period checks, see Dates and Times.

Boolean

true
false

Combine with and, or, not — see Logical Operators.

Type checking

When you save a rule, BGL checks types. If you compare a number to a text value, or assign a date to a numeric field, the editor flags the error and the rule won’t save until you fix it.

# Error — comparing text to a number
when order.id > 100 then ... end

# Fixed — cast the field to a number first
when order.id as number > 100 then ... end

Casting

Convert a value from one type to another with as <type>:

Cast Example
as number order.custom.qty as number
as text order_line.qty_ordered as text
as date order.custom.date_string as date
as boolean order.custom.flag as boolean

Casting fits into expressions:

set order.notes to "Total: " & order.subtotal as text
when order.custom.priority as number > 5 then ... end

Common cases for casting

  • A custom field that came in as text but represents a number. Often custom fields are loaded as text from external systems even when they look numeric. as number lets you do math on them.
  • Building a string from a number. Concatenation requires text. order.id as text & " is the ID" works; order.id & " ..." may not, depending on the field’s type.
  • A date that arrived as a string. External systems sometimes deliver dates as text. as date parses them.

What’s not supported

BGL doesn’t have:

  • Type-specific functions — no length() for strings, no abs() for numbers, no year() for dates. Work around with regex (for strings), arithmetic (for numbers), period checks like is_in @2024 (for dates).
  • Lists or arrays as a first-class type. Collections exist (line items, etc.) but you don’t store one in a variable. Iterate them with for, summarize them with accumulate, or check them with quantifiers.
  • Custom types or structs. Each value is one of the four basic types or a model/collection.
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.