Tape calculation field Cheat Sheet

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 :crystal_ball:



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




Developer documentation and advise

Debugging and testing

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

Performance considerations

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!)

5 Likes