Introduction to named formulas

Imagine a world where you could define a single formula and then reference it throughout your app, just like you do with variables. That's the beauty of Named Formulas. They act as reusable snippets of code that you can easily call upon, reducing redundancy and streamlining your app development process.

Benefits of using named formulas

How to use named formulas

Components

Examples of named formulas in action


1. Complex calculations

Named Formula:
TotalCost = Quantity * UnitPrice + (Quantity * UnitPrice * TaxRate);
// Use TotalCost in a label or text box:
Label1.Text = "Total Cost: " & TotalCost

2. Data validation

NamedFormula: 
IsValidEmail = IsMatch(TextInput1.Text, EmailRegex);
// Use IsValidEmail to enable or disable a button:
Button1.DisplayMode = If(IsValidEmail, DisplayMode.Edit, DisplayMode.Disabled)

3. Data transformation

NamedFormula:
FullName = Concat(FirstName, " ", LastName)
// Use FullName in a display field or email template:
GreetingLabel.Text = "Hello, " & FullName

4. Conditional formatting

Named Formula:
Overdue = DateDiff(Today(), DueDate) > 0
// Use Overdue to set the background color of a label:
Label2.Fill = If(Overdue, Red, LightGray)

5. Lookup values

NamedFormula:
  UserInfo = LookUp(Users, 'Primary Email' = User().Email)
  UserTitle = UserInfo.Title
  UserPhone = Switch(
    UserInfo.'Preferred Phone',
      'Preferred Phone (Users)'.'Mobile Phone', UserInfo.'Mobile Phone',
      UserInfo.'Main Phone'
  )
)
// Use UserTitle and UserPhone in labels or other controls:
Label3.Text = "Welcome, " & UserTitle & "!"

Key points to remember