I'm intending to create a simple AirTable script to record duration of a single status field. In my use case I'm tracking a large number of issues where the status frequently goes back and forth between the multiple status',
For example there are multiple status': open, in-progress, and resolved status. A normal workflow would be non-linear, so a record could go from open to in-progress, back to open, then to resolved then back to open, and then finally to resolved again.
open > in-progress > open > resolved > open > resolved.
I'd like to track the duration that each record is in each status as well as the cumulative time each record is in each status. This way I could say this record was open for a period of 3 days, in progress for 1 day and it was in a resolved status two days.
In the first table I have several records with a status field and a time modified field as well as other important data fields to help identify the issue, like name and the primary key. As well as a field for each cumulative status duration.
My second table is a log recording the status and the time it was modified. This table can be used for historical data. It record the time that the status has started on each status and when it has ended each status, as well as the duration in days.
I'd like to do this whole project with AirTable Scripting. And I have a good start so far, thanks to Ben from the Airtable community. But I still have a little ways to go.
// read the current status of a record
const table = base.getTable("Item Status");
const records = await table.selectRecordsAsync({
fields: ["Current Status"]
})
.then(query => query.records);
let record = records[0];
console.log(record.getCellValueAsString('Current Status'));
// record the last modified time of a record
//const table = base.getTable("Item Status");
const records2 = await table.selectRecordsAsync({
fields: ["Last Modified Time"]
})
.then(query => query.records);
let record2 = records2[0];
console.log(record2.getCellValueAsString('Last Modified Time'));
At the moment I can get both the status and the date modified but now I need to "write" that data for record into my log table.
Also, a major issue I'm finding is that I'm not able to have the single select option be the trigger for the automation. I'd imagine when I can the status of the field "current status" from Open to In-Progress, this would trigger the automation to run the script. (At the moment I have this setup through an automation, and it works but I'd like to do this via scripting.)