Scripting
Example

Custom report
Scripting Extension only

This script filters the records in a table and generates a report that summarizes the data. You can adapt it by changing the filter conditions, or use it as a starting point for advanced reports and analysis.

Example
let table = base.getTable('Design projects');
let result = await table.selectRecordsAsync({fields: ['Name', 'Category', 'Project lead', 'Client', 'Complete']});
output.markdown('# Project report generator');
let type = await input.buttonsAsync(
'Which report would you like to generate?',
[
'Completed Projects',
'Incomplete Projects',
],
);
output.clear();
output.markdown(`# ${type} Report`);
let records;
if (type === 'Completed Projects') {
records = result.records.filter(record => record.getCellValue('Complete'));
} else {
records = result.records.filter(record => !record.getCellValue('Complete'));
}
function countByField(records, groupByField) {
let counts = {};
for (let record of records) {
let key = record.getCellValueAsString(groupByField);
if (key in counts) {
counts[key] = counts[key] + 1;
} else {
counts[key] = 1;
}
}
return counts;
}
output.markdown('## Categories');
let categoryCounts = countByField(records, 'Category');
output.table(categoryCounts);
output.markdown('## Projects');
output.table(
records.map(record => ({
Name: record.getCellValue('Name'),
Category: record.getCellValue('Category'),
'Project lead': record.getCellValue('Project lead'),
Client: record.getCellValue('Client'),
})),
);
output.markdown(`**Total**: ${records.length}`);