Java Automation

Topic Labels: Automations
526 1
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

I am trying to get a sum total of a column in an automation that will send out an email showing the new total every time an amount is added. I was tasked to create an automation running a script, but I am very new to script writing. Any help would be most appreciated

1 Reply 1

This mornings coffee break, I created this example using a Scripting Extension - once you have an understanding of this, we can then talk about how to gear it within an Automation Script (which will be a very similar exercise, with minor differences).

The key to this is using the Javascript reduce() method. I've also demonstrated how you can filter the data using a filter() method, before the data is summed via reduce().

const emailTable = base.getTable("Numbers Table");

let records = await emailTable.selectRecordsAsync({
	fields: ["Fruit", "Total Mass"]

let initialValue = 0;
let sumMass = records.records
		(record) => !== "Green Apple"
	.reduce((accumulator, record) => record.getCellValue("Total Mass") + accumulator, initialValue);


Here, we can see the data that's been filtered, then reduced - and the final total;