Help

The Community will be undergoing maintenance from Friday February 21 - Friday, February 28 and will be "read only" during this time. To learn more, check out our Announcements blog post.

A summary table utility I created

Topic Labels: Automations Formulas Views
195 1
cancel
Showing results for 
Search instead for 
Did you mean: 
JeffJohnVol
7 - App Architect
7 - App Architect

Here's something I created using automations with a script to allow me to get quick totals on any table view for specific values. I have 2 cases listed below and have found it to be a great way of collecting totals without having to create other linked records, rollups etc. Of course I have to hit the recalculate checkbox to get my total for each row, so it's not live, but I can live with that.  Also, you have to make sure your references are correctly spelled (Source Table, Source View, etc).  I hope others find it useful. I've attached the javascript below.

JeffJohnVol_0-1739373291122.png

JeffJohnVol_1-1739373483369.png

let inputConfig = input.config();

let record_id = inputConfig['SummaryRecID'];

// Reference the "Summary Table"
let summaryTable = base.getTable("Summary Table");

// Fetch the specific record in "Summary Table"
let summaryRecord = await summaryTable.selectRecordAsync(record_id, {
    fields: ["Source Table", "Source View", "Field", "Value"]
});

if (!summaryRecord) {
    console.log("Record not found in Summary Table.");
    return;
}

// Load field values from the "Summary Table"
let sourceTblName = summaryRecord.getCellValue("Source Table");
let sourceVwName = summaryRecord.getCellValue("Source View");
let sourceFldName = summaryRecord.getCellValue("Field");
let sourceVal = summaryRecord.getCellValue("Value");

// Ensure all required fields exist
if (!sourceTblName || !sourceVwName || !sourceFldName || sourceVal === null) {
    console.log("Missing required field values in Summary Table.");
    return;
}

// Convert `sourceVal` to string in case it's a Single Select
if (typeof sourceVal === "object" && sourceVal !== null && "name" in sourceVal) {
    sourceVal = sourceVal.name;
}

// Get the table object dynamically
let sourceTable = base.getTable(sourceTblName);

// Get the view object dynamically
let sourceView = sourceTable.getView(sourceVwName);

// Fetch records from the specified view
let sourceQuery = await sourceView.selectRecordsAsync({ fields: [sourceFldName] });

let count = 0;

// Loop through records in the source view and count matches
for (let record of sourceQuery.records) {
    let fieldValue = record.getCellValue(sourceFldName);

    // Handle Single Select fields (extract name)
    if (typeof fieldValue === "object" && fieldValue !== null && "name" in fieldValue) {
        fieldValue = fieldValue.name;
    }

    // Compare values (ensuring type safety)
    if (fieldValue !== null && fieldValue.toString() === sourceVal.toString()) {
        count++;
    }
}

// Update the "Count" field in "Summary Table" for the given record_id
await summaryTable.updateRecordAsync(record_id, {
    "Count": count
});

console.log(`Updated count to ${count} for record ${record_id}`);

 

Jeff Johnson
President, ChattLab Makerspace
1 Reply 1
Milan_Automable
6 - Interface Innovator
6 - Interface Innovator

Cool!

Best,
Milan - automable.ai
Free Airtable consultation