Back to Nocobase

Formula

docs/docs/en/data-sources/field-formula/index.md

2.1.285.3 KB
Original Source

Formula

Introduction

In NocoBase, Formula calculates a field value from an expression.

It is suitable for amount calculations, score calculations, text concatenation, and conditional calculations. Its value is normally generated by an expression and is not suitable for manual entry. For complex calculations, use a workflow or database view.

Use cases

Formula fields are suitable for these business scenarios:

  • Amount calculations
  • Score calculations
  • Text concatenation
  • Conditional calculations

Create and configure

On the collection's Configure fields page, click Add field and select Formula to create this field.

SettingDescription
Field interfaceThe field interface. Formula uses formula, which determines how the field is entered and displayed in pages.
Field display nameThe name displayed for the field, such as Order subtotal, Overall score, or Display name. Use a name that business users can recognize.
Field nameThe field identifier used internally by APIs, relation fields, permissions, and workflows. It usually cannot be changed after creation. It supports only letters, numbers, and underscores, and must begin with a letter.
Field typeThe data-layer type. Formula uses formula by default.
Default valueThe default value. When a new record has no value, NocoBase can fill this value automatically.
Validation rulesValidation rules. Confirm that the formula expression is complete and referenced fields exist.
DescriptionA field description. Record the field meaning, entry requirements, data source, or maintainer.

:::warning Note

Field names are referenced by page blocks, permissions, workflows, and APIs after creation. Confirm the name before creating the field to avoid later configuration changes.

:::

Field behavior

The default behavior of a Formula field is as follows:

BehaviorDescription
Default Field interfaceformula.
Default Field typeformula.
Available Field typesformula.
Page componentDisplays the result calculated from a formula expression.
FilteringFiltering depends on the formula result and data-source capabilities.
SortingSupports sorting where the formula result type permits.
ValidationConfirm that the formula expression is complete and referenced fields exist.

Edit configuration

After creation, click Edit beside the field to edit its configuration. Edit fields to adjust how they are displayed and used in NocoBase, such as the display name, description, default value, validation rules, or field-specific settings.

When a field comes from a synchronized main-database table, editing usually maps the database field to a NocoBase Field type and Field interface.

SettingCan be editedDescription
Field display nameYesChanges the name displayed in the interface without changing the field identifier.
Field nameNoThe field identifier normally cannot be changed in the edit form after creation.
Field interfaceConditionalMain-database fields and synchronized fields can be adjusted during field mapping. Changes affect page input, display, and validation.
Field typeConditionalMain-database fields and synchronized fields can be adjusted during field mapping. Confirm that existing values can be used by the new type first.
Default valueYesAdjusts the default value for new records.
Validation rulesYesAdjusts field validation rules.
DescriptionYesAdds the field meaning, entry requirements, data source, or maintainer.

:::warning Note

Changing a Field type or Field interface is more than changing a display name. It affects field storage, input components, validation rules, filters, and workflow-variable usage. When the field contains substantial existing data, confirm that its data format is compatible first.

:::

Delete field

Click Delete beside a Formula field to delete it. You can also select multiple fields and delete them in the main data source.

Deleting a Formula field created in the main database usually also deletes the actual database column and its values. For a synchronized or external-data-source field, the impact depends on the corresponding data source and field origin.

:::danger Warning

Deleting a field can affect page blocks, forms, filters, permissions, workflows, APIs, imports and exports, and existing data. Confirm that the field is no longer referenced by business configuration before deleting it.

:::

Use in pages

Formula fields are suitable for calculated values in pages, reports, and business logic.

ScenarioUse
Details blockDisplay a calculated value.
Table blockDisplay and sort a formula result where supported.
ChartsUse a formula result for presentation.
Workflows and APIsRead calculated values in business logic.