Expression Fields Reference

Reftab’s calculated expression fields allow you to build dynamic, calculated fields using placeholders, operators, and functions.

Placeholder Basics

Placeholders substitute field values from the current asset into your expression. Wrap any field name in double curly braces.

// Substitute a field value
{{serialNumber}}                     → SN-00452

// Multiple placeholders
{{make}} {{model}}                   → Dell XPS 15

// Concatenate with a space
{{first}} + " " + {{last}}           → John Smith

// Numeric operations
{{quantity}} + {{spares}}            → 15
{{width}} * {{height}}               → 200
{{total}} / 3                        → 33.33

Case Sensitive: Placeholder lookup is case sensitive. {{cost}} and {{Cost}} reference different fields.

Missing Placeholders

Missing placeholders resolve to null. Add fallback logic when a value is optional:

// Use fallback if field is missing
{{nickname}} ?? {{displayName}}      → displayName if nickname is null
{{optional}} || "Not provided"       → "Not provided" if optional is empty

Context Variables

Special context variables provide access to related location and loan data using dotted placeholders.

$location

Access the asset’s location hierarchy:

VariableDescription
{{$location.name}}Current location name
{{$location.parentLocationName}}Parent location name
{{$location.grandparentLocationName}}Grandparent location name
{{$location.greatGrandparentLocationName}}Great-grandparent location name
// Display full location path
{{$location.parentLocationName}} + " > " + {{$location.name}}
→ Building A > Room 101

// Fallback through location hierarchy
{{$location.grandparentLocationName}} ?? {{$location.parentLocationName}} ?? {{$location.name}}
→ Returns the highest available level

$loan

Access checkout and loanee details for assets currently on loan:

VariableDescription
{{$loan.check_out}}Date the asset was checked out
{{$loan.due}}Loan due date
{{$loan.lid}}Loan ID
{{$loan.lgid}}Loan group ID
{{$loan.loanee}}Loanee identifier
{{$loan.loaneeName}}Name of person who has the asset
{{$loan.loaneeTitle}}Loanee’s title
{{$loan.loanerEmail}}Loanee’s email address
{{$loan.lnid}}Loan note ID
{{$loan.loan_uid}}Loan unique ID
{{$loan.thumbnail}}Loanee’s thumbnail image
// Display who has the asset
"Checked out to: " + {{$loan.loaneeName}}
→ Checked out to: Jane Doe

// Show loanee with title
{{$loan.loaneeName}} + " (" + {{$loan.loaneeTitle}} + ")"
→ Jane Doe (IT Manager)

// Display due date
"Due: " + {{$loan.due}}
→ Due: 2024-04-15

Standard Math Operations

Math expressions containing numerics, parentheses, and operators + - * / % are evaluated with normal precedence after placeholders resolve. Unary +/- are supported for negative numbers.

// Basic arithmetic
{{quantity}} + {{spares}}            → 15
{{total}} - {{discount}}             → 85
{{price}} * {{quantity}}             → 499.50
{{total}} / 4                        → 25

// Modulo (remainder)
{{count}} % 5                        → 2

// Negative values
-{{debt}} + 10                       → -90

// Grouped operations (parentheses)
({{a}} + {{b}}) * {{c}}              → 30
{{a}} + {{b}} * {{c}}                → 22 (multiplication first)

// Area calculation
{{width}} * {{height}}               → 200

// Calculate total with tax
{{price}} + ({{price}} * 0.08)       → 107.99

Type Error: Operands that cannot be coerced to numbers will throw an error. Add quotes or fallback logic when combining strings with numerics.

Text Filters

Apply filters after a placeholder using the pipe (|) operator. Multiple filters chain from left to right.

// Convert to uppercase
{{code | uppercase}}                 → ABC-123

// Convert to lowercase
{{name | lowercase}}                 → john doe

// Convert to title case
{{fullName | titlecase}}             → John Doe

// Chain multiple filters
{{name | lowercase | titlecase}}     → John Doe

// Filter on status field
{{status | uppercase}}               → ACTIVE

// Combine with concatenation
"Status: " + {{status | uppercase}}  → Status: ACTIVE

Date Math

Add or subtract time from date values. Date offsets work on either side of the operator.

// Add years (calculate warranty expiry)
{{purchaseDate}} + 5 years           → 2029-01-15

// Add months
{{startDate}} + 6 months             → 2024-07-15

// Add weeks
{{orderDate}} + 2 weeks              → 2024-02-01

// Add days
{{createdDate}} + 30 days            → 2024-02-14

// Add hours
{{startTime}} + 3 hours              → 2024-01-15 11:00

// Subtract time
{{shipDate}} - 2 weeks               → 2024-01-01
{{expiryDate}} - 6 months            → 2023-07-15

// Offset on left side
3 months + {{purchaseDate}}          → 2024-04-15

// Calculate review date (90 days from purchase)
{{purchaseDate}} + 90 days           → 2024-04-14

Comparisons and Truthiness

Use comparison operators to build boolean logic. Truthy/falsy follow PHP rules: non-empty strings and non-zero numbers are truthy.

Comparison Operators

// Equality
{{status}} == "retired"              → true
{{status}} == "active"               → false

// Inequality
{{status}} != "active"               → true

// Numeric comparisons
{{quantity}} > 10                    → true
{{quantity}} >= 10                   → true
{{count}} < 5                        → false
{{count}} <= 5                       → true

Logical Operators

// OR - returns first truthy value
{{primary}} || {{secondary}}         → primary (if truthy)
{{nickname}} || {{fullName}}         → fullName (if nickname empty)
{{value}} || "default"               → "default" (if value empty)

// Null coalescing - returns first non-null (keeps empty strings)
{{nickname}} ?? {{displayName}}      → "" (if nickname is empty string)
{{optional}} ?? "fallback"           → "fallback" (if optional is null)

Conditionals

Branch inside an expression to return different values based on conditions. These constructs can nest; each branch is itself an expression that can include placeholders, filters, or more conditionals.

Function Style

// $if(condition, valueIfTrue, valueIfFalse)
$if({{status}} == "retired", "Do not loan", "Available")
→ "Do not loan"

$if({{quantity}} > 0, {{name}}, "Out of stock")
→ "Laptop" or "Out of stock"

$if({{checkedOut}}, "Checked Out", {{status}} | uppercase)
→ "Checked Out" or "AVAILABLE"

Ternary Operator

// condition ? valueIfTrue : valueIfFalse
{{checkedOut}} ? "Checked out" : "On shelf"
→ "Checked out" or "On shelf"

{{quantity}} > 0 ? "In stock" : "Sold out"
→ "In stock" or "Sold out"

{{isActive}} ? {{name}} : "Inactive: " + {{name}}
→ "Laptop" or "Inactive: Laptop"

Nested Conditionals

// Multiple levels of conditions
{{a}} ? ({{b}} ? "both" : "a only") : "neither"
→ "both", "a only", or "neither"

$if({{quantity}} > 100, "High", $if({{quantity}} > 10, "Medium", "Low"))
→ "High", "Medium", or "Low"

Fallback Patterns

// Null coalescing - first non-null value
{{nickname}} ?? {{displayName}}
→ Uses nickname if not null, otherwise displayName

// Logical OR - first truthy value
{{primary}} || {{secondary}}
→ Uses primary if truthy, otherwise secondary

// Multi-level fallback
{{nickname}} ?? {{preferredName}} ?? {{fullName}}
→ First non-null value in chain

String Handling

Understanding string concatenation and type coercion helps avoid unexpected results.

// Basic concatenation
{{make}} + " " + {{model}}           → "Dell XPS 15"

// Quoted strings preserve spacing
"Asset: " + {{name}}                 → "Asset: Laptop"

// Escape quotes inside strings
"A \"quoted\" label"                 → A "quoted" label

// Plus signs inside quotes are literal text
"1 + 1 = 2"                          → "1 + 1 = 2"

// String coercion: if one side is a string, both become strings
"Total: " + {{price}} + {{tax}}      → "Total: 9910" (not math!)

// Use parentheses to force math first
"Total: " + ({{price}} + {{tax}})    → "Total: 109"

// Area with unit label
"Area: " + ({{width}} * {{height}}) + " sq ft"
→ "Area: 200 sq ft"

// Arrays or objects resolve to empty string
{{items}} + " items"                 → " items" (if items is an array)

Start tracking your assets in minutes. Free forever.

50 assets free forever with unlimited inventory & software tracking. Includes email alerts, mobile apps, reports, custom asset tags and more.