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 column.
Example
formatDateWithMinutes
Format date to 'YYYY-MM-DD HH:mm' to be used in a date column..
Example
Lookup and Query¶
lookupAndCopy
Similar to the vlookup function in Excel. 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.
Name | |
---|---|
Hulk | greenbigboy@stark-industries.movie |
Tony | ironman |
The target table only has the user names but we want to copy the email address from the source table to the target table, then this function can be used.
Name | |
---|---|
Hulk | |
Tony |
base.utils.lookupAndCopy(targetTable, targetColumn, targetColumnToCompare, sourceTableName, sourceColumnName, sourceColumnToCompare = null);
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', 'Name');
// 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 summary the table data by SQL like 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', 'View_name', 'select sum(number), sum(number2) where number + number1 + number2 > 5');