let table = base.getTable('Design projects'); let result = await table.selectRecordsAsync(); 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}`);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter