Utility functions¶
Utility functions help you to work with data in SeaTable.
Date and Time¶
formatDate
Format date to 'YYYY-MM-DD' to be used in a date-type column.
Output String
Example
formatDateWithMinutes
Format date to 'YYYY-MM-DD HH:mm' to be used in a date-type column.
Output String
Example
Lookup and Query¶
lookupAndCopy
Similar to the Microsoft Excel VLOOKUP function. Find a matching row in the source table for each row of the target table, and then copy the data of the specified cell of the matching row to the specified cell of the target row. Every arguments are String.
base.utils.lookupAndCopy(targetTable, targetColumn, targetColumnToCompare, sourceTableName,
sourceColumnName, sourceColumnToCompare = null /* (1)! */);
-
targetTable: the name of the target table - i.e. the table you want to copy data intotargetColumn: the column oftargetTableyou want to copy data intotargetColumnToCompare: the column oftargetTableyou want to compare to a column of tablesourceTableNamesourceTableName: the source table - i.e. the table you want to copy data fromsourceColumnName: the column ofsourceTableNameyou want to copy data fromsourceColumnToCompare: If specified, the column ofsourceTableNameyou want to compare withtargetColumnToCompareto find matching rows. If not specified, the system will look for a column with the nametargetColumnin the tablesourceTableName
Output Nothing (throws an error if some tables or columns do not exist)
Principle example
Here are two tables, the source table containing both names and emails for few Avengers whereas the target table only has the user names.
Source table
| Name | SourceEmail |
|---|---|
| Hulk | greenbigboy@stark-industries.movie |
| Tony | ironman |
Target table
| Name | TargetEmail |
|---|---|
| Hulk | |
| Tony |
To copy the email addresses from the source table to the target table, this function can be used with the following syntax:
Example
// Match the rows with the same content in the Name column of Table1 and Table2,
// copy the contents of the Email column of the row in Table1 to the Email column
// of the corresponding row in Table2
base.utils.lookupAndCopy('Table2', 'Email', 'Name', 'Table1', 'Email');
// Match the rows with the same content in the Name column in Table1 and the Name1 column
// in Table2, and copy the contents of the Email column of the row in Table1 to the
// Email1 column of the corresponding row in Table2
base.utils.lookupAndCopy('Table2', 'Email1', 'Name1', 'Table1', 'Email', 'Name');
query
Filter and summarize the table tableName data of the view viewName by SQL like query statements.
Example
// Filter out the rows where the sum of the three columns 'number', 'number1',
// and 'number2' is greater than 5 then sum the number and number2 columns in these rows,
// return {number: 12, number2: 23}
base.utils.query('Table1', 'Default View', 'select sum(number), sum(number2) where number + number1 + number2 > 5');