Skip to main content

Formula

Overview

A Formula is a Logic Block that accepts one or more inputs and produces a single output value. Despite the name, a Formula is not limited to mathematical computations—it can perform string manipulation, DateTime computation, data lookups, or any calculation that produces a single result.

Formulas are the most basic and versatile Logic Block type. They're ideal for:

  • Mathematical calculations (totals, percentages, averages)
  • String operations (formatting, concatenation, extraction)
  • Date calculations (age, duration, deadlines)
  • Conditional expressions (if-then-else logic)
  • Data lookups (retrieving values from related records)

Structure

A Formula consists of:

ComponentDescription
NameUnique identifier for the formula
DescriptionWhat the formula calculates
InputsOne or more typed input parameters
OutputA single typed output value
ExpressionThe calculation logic

Expression Language

Formula expressions are written using the FlowOn Expression Language—a comprehensive library of over 200 functions and operators for calculations, transformations, and data manipulation.

The Expression Language includes:

  • Operators: Arithmetic, comparison, logical, and string operators
  • Text Functions: String manipulation, formatting, searching, and extraction
  • Numeric Functions: Mathematical operations, rounding, aggregation
  • Date & Time Functions: Date arithmetic, formatting, extraction, and comparison
  • Logical Functions: Conditional expressions, null handling, type checking
  • Entity Functions: Record retrieval, field access, relationship navigation
  • Collection Functions: List operations, filtering, aggregation
  • Conversion Functions: Type conversion, parsing, formatting
Expression Language Reference

For complete documentation of all functions, operators, and syntax, see the FlowOn Expression Language Reference.

Example: Calculate Order Total

Name: CalculateOrderTotal

Inputs:

  • Quantity (Integer): Number of items
  • UnitPrice (Money): Price per item
  • DiscountPercent (Decimal): Discount to apply
  • TaxRate (Decimal): Tax rate

Output:

  • Total (Money): Final order total

Expression:

Subtotal = Quantity * UnitPrice
DiscountAmount = Subtotal * (DiscountPercent / 100)
TaxableAmount = Subtotal - DiscountAmount
TaxAmount = TaxableAmount * (TaxRate / 100)
Total = TaxableAmount + TaxAmount

Example: Calculate Customer Age

Name: CalculateAge

Inputs:

  • BirthDate (DateTime): Customer's birth date

Output:

  • Age (Integer): Customer's age in years

Expression:

DATEDIFF(BirthDate, TODAY()) / 365

Example: Format Full Name

Name: FormatFullName

Inputs:

  • FirstName (String): First name
  • MiddleName (String): Middle name (optional)
  • LastName (String): Last name

Output:

  • FullName (String): Formatted full name

Expression:

IF(MiddleName != null && MiddleName != "",
CONCAT(FirstName, " ", MiddleName, " ", LastName),
CONCAT(FirstName, " ", LastName))

Example: Calculate Days Until Due

Name: DaysUntilDue

Inputs:

  • DueDate (DateTime): The due date

Output:

  • DaysRemaining (Integer): Number of days until due (negative if overdue)

Expression:

DATEDIFF(TODAY(), DueDate)

Example: Determine Shipping Cost

Name: CalculateShipping

Inputs:

  • OrderWeight (Decimal): Total weight in kg
  • ShippingZone (String): Destination zone
  • IsExpedited (Boolean): Express shipping requested

Output:

  • ShippingCost (Money): Calculated shipping cost

Expression:

BaseRate = IF(ShippingZone == "Local", 5.00,
IF(ShippingZone == "Regional", 10.00,
IF(ShippingZone == "National", 15.00, 25.00)))

WeightCharge = OrderWeight * 0.50

ExpeditedMultiplier = IF(IsExpedited, 2.0, 1.0)

ShippingCost = (BaseRate + WeightCharge) * ExpeditedMultiplier

Example: Lookup Customer Discount

Name: GetCustomerDiscount

Inputs:

  • CustomerId (Entity Reference): Reference to the Customer record

Output:

  • DiscountPercent (Decimal): Customer's discount percentage

Expression:

Customer = GET_ENTITY("contact", CustomerId)
Tier = Customer.CustomerTier

DiscountPercent = IF(Tier == "Platinum", 20,
IF(Tier == "Gold", 15,
IF(Tier == "Silver", 10, 0)))

Best Practices

Keep Formulas Focused: Each Formula should calculate one thing. If you need multiple related outputs, consider using a Decision Table instead.

Use Meaningful Names: Name your Formula based on what it calculates: CalculateOrderTotal, FormatAddress, DetermineEligibility.

Document Your Inputs: Use clear input names and descriptions so others understand what data to provide.

Handle Null Values: Always consider what happens if an input is null. Use IF statements or null-coalescing functions to handle missing data gracefully.

Break Down Complex Logic: If your expression becomes long and hard to read, consider splitting it into intermediate variables within the expression, or breaking it into multiple Formulas.

Test Edge Cases: Test your Formula with boundary values, null inputs, and unexpected data to ensure it behaves correctly in all scenarios.