EspoCRM Formula Data Quality Tutorial

Capitalize the First Letter with EspoCRM Formula

Eymen Elkum headshot Eymen Elkum
EspoCRM Formula script transforming a lowercase value into a capitalized value

Normalize an EspoCRM text field by capitalizing its first character with a null-safe Formula script tested in Formula Sandbox.

EspoCRM Formula can normalize a text field before a record is saved. This example capitalizes only the first character and leaves the remainder unchanged.

For example:

hello world → Hello world

It does not convert every word to title case.

Before you begin

You need administrator access to Formula Sandbox and Entity Manager. Test the expression against representative records in a non-production environment before adding it to an entity’s before-save Formula, because the saved rule will normalize every future matching record save.

Step 1: Test the expression in Formula Sandbox

Open Administration → Formula Sandbox and select the entity type that contains the target field.

For a field whose internal name is name, test:

if (name != null && string\length(name) > 0) {
    name = string\concatenate(
        string\upperCase(string\substring(name, 0, 1)),
        string\substring(name, 1)
    );
}

The condition avoids calling string functions with a null or empty value.

EspoCRM Formula Sandbox successfully running the first-letter capitalization formula

Formula Sandbox validates the script against a selected record without saving it.

How the formula works

  1. string\length confirms that the value contains at least one character.
  2. string\substring(name, 0, 1) extracts the first character.
  3. string\upperCase converts that character to uppercase.
  4. string\substring(name, 1) returns the remaining text.
  5. string\concatenate joins both parts and assigns the result to name.

Step 2: Add it to the entity

  1. Open Administration → Entity Manager.
  2. Select the target entity.
  3. Open Formula.
  4. Add the script to Before Save Custom Script.
  5. Save the Formula configuration.

Replace name with the field’s internal name when normalizing another Varchar or Text field.

Step 3: Test record saves

Test at least these values:

InputExpected output
hello worldHello world
Hello worldHello world
hH
emptyempty
nullnull
123 service123 service

Also test characters used by your users’ languages. Case conversion can vary by language and character set, so confirm the result with real representative values.

Apply the rule only when needed

To avoid assigning the field on every save, add an attribute-change condition:

if (
    entity\isAttributeChanged('name') &&
    name != null &&
    string\length(name) > 0
) {
    name = string\concatenate(
        string\upperCase(string\substring(name, 0, 1)),
        string\substring(name, 1)
    );
}

Use this version when the formula runs on existing records that are frequently updated for unrelated reasons.

Common problems

The formula changes only the first word

That is the intended behavior. This formula capitalizes the first character of the complete value; it does not title-case every word.

The field is not changed

Confirm that you used the internal field name shown under Administration → Entity Manager → Fields, not its translated label.

Imports contain inconsistent values

Before-save Formula applies when imported records are saved. Test the import with a small file and confirm whether your selected import options run the entity’s save logic.