This site is a comprehensive reference for creating, using, and debugging Tape calculation field scripts.

In a Tape database, you can add a calculation field that lets you run all kinds of calculations and functions based on other fields. You can use calculation fields to manipulate existing data and yield many other helpful values. The utility of Tapeβs calculation field is virtually endless; youβll start with simple, common applications and gradually expand the way you use it. At the highest level, you can see what the community creates within the real-world use case examples

*CONTENTS*

*Basics β*

*Setting up a calculation field β*

*Examples for a calculation field β*

*Developer documentation and advise β*

*Limitation β*

*Real-world Use Case Examples β*

## Basics

#### Purpose and functionality

- Dynamic calculations: the calculation field dynamically computes values based on other data within your Tape app (and also related apps). This feature is particularly useful for automating calculations that would otherwise be manually performed.
- Updates: calculations update as the input fields change, ensuring that the data displayed is always current.

#### Supported calculations

- Basic arithmetic: add, subtract, multiply, and divide values.
- Date and time calculations: calculate differences between dates, add or subtract time, etc.
- Text manipulation: concatenate text, extract substrings, convert formats, etc.
- Advanced: many more advanced logic, with the unlimited power of scripting

#### Language

- JavaScript-Based: The calculations are scripted in modern ES2021 JavaScript, offering a versatile range of programming functionalities and current syntax

## Setting up a calculation field

#### Adding a calculation field:

β Intro to field types | Tape Help Center

#### Writing calculations

- Use JavaScript syntax, keeping in mind that fields from Tape are referenced using
`@FieldName`

. - Example: To add two number fields,
`@Number1`

and`@Number2`

, the script would be`@Number1 + @Number2`

.

#### Syntax Tips

- String Handling: Use quotes for text, e.g.,
`"Hello" + " " + "World"`

. - Conditional Statements: Implement logic using
`if...; else`

statements. - Functions: Utilize JavaScript functions for more complex operations.

## Examples for a calculation field

#### Setting up basic calculations

- How to Do It: Use the β@β symbol to refer to other fields.
- Example: To add two number fields, use
`@Number1 + @Number2`

.

#### Arithmetic calculation

- Example: calculate the total cost by multiplying quantity and unit price.
- Script:
`@Quantity * @Unit Price`

#### Text manipulation

- Example: create a full name from first and last names.
- Script:
`@FirstName + " " + @LastName`

- Script:
`@FirstName + " | " + @LastName`

- Script:
`@LastName + ", " + @FirstName`

#### Using conditional calculations

- Description: change the result based on certain conditions.
- Example:
`if(@Field > 10) "High"; else "Low"`

.

#### Incorporating else if statements

- Purpose: specify a new condition if the first one is false.
- Example:
`if(@Field > 10) "High"; else if(@Field > 5) "Medium"; else "Low"`

.

#### Implementing if and statements

- How It works: combine multiple conditions.
- Example:
`if(@Field1 > 10 && @Field2 < 5) "Yes"; else "No"`

.

#### Working with text fields in calculations

- Key use: combine text fields and handle empty values.
- Example:
`@TextField1 + " " + @TextField2`

.

#### Utilizing calculations with relationships

- Function: count related items or perform other relationship-based calculations.
- Example: counting related items with
`@RelatedItems.length`

.

#### Handling Calculations with Dates and Numbers

- Focus: Calculate durations, end dates, and handle decimals.
- Example:
`date_fns.differenceInDays(@EndDate, @StartDate)`

. - More details: π Working with dates in calculation fields

## Developer documentation and advise

#### Debugging and testing

- Regularly check for syntax errors.
- Test with different data inputs to ensure reliability.

#### Performance considerations

- Simplify calculations where possible.
- Be cautious of creating calculations that reference a large number of fields.
- Available Libraries (Calculation field) | Tape Developers
- Markdown Support | Tape Developers
- HTML & CSS Support | Tape Developers
- Links | Tape Developers
- Buttons | Tape Developers
- Some general advise: [β Solution] Calculation fields best practices? - #3 by Tim

#### Documentation and Comments

- Use comments in your scripts to explain the purpose and functionality of complex calculations.

## Limitation

#### Complexity and Dependencies

- Calculations are limited by the complexity of JavaScript that Tape can handle.
- Changes in field names or types can break existing calculations.

#### Performance Impacts

- Overly complex or numerous calculations can slow down app performance.

## Real-world use case examples (Big thanks to the community!)

- How to create a link to scroll to a field inside a record via the calculation field (Anchor Link)
- How to embed PDF attachments into the record using the calculation field
- The power of JSON to generate your dynamic data in calculation field
- [β Solution] Formatted ID in calculation field
- [β Solution] How to create a table in a calculated field?
- [β Solution] Calculations to create header/sections disappear after refreshing or logging in and out - #5 by arvylee
- [β Solution] Calculate Calculate the most recent creation date of all related entries
- Convert Raw JSON (in Multi Text Field) to Table in Calculation
- Icon from status field in calculation field
- π Leverage clickable calculation field links in list and board layouts