Help

Re: Record timer script

6186 0
cancel
Showing results for 
Search instead for 
Did you mean: 

Inspired by this discussion, I wrote a script for the Scripting block that lets you instantly start and stop a virtual timer on any record, provided that the table is set up to work with this script. Aside from adding the script into a Scripting block, setup only requires three new fields:

  1. A single line text field, which will store the script’s timing data (used internally; may be hidden)
  2. A duration field, where the script will store the tracked time
  3. A button field, which must be set to trigger the Scripting block that contains the script. I suggest labeling this button “Start/Stop,” for reasons that you’ll see below.

Use: Click the button once to start the “timer.” Click it again to stop it and see the duration. Need to continue timing on that same record? Click the button again to restart. The next click after that will tally the elapsed time from both timing “sessions” and put the total in the duration field. Start and stop the timer as much as you need.

How it works: Each time you click the button, the script adds the current time (converted to a number) to an array, and stores that array in the single line text field. An time that a button click results in an even number of values in the array, the script calculates the difference between each pair of values, and stores the resulting duration in the duration field.

The benefit of this timer system is that you can have multiple records all “timing” simultaneously, and all using the same Scripting block. Using Airtable’s timer block, you first have to pick a record for the timer, and you need one timer block per record that you wish to time.

One optional feature in the script is to clear the duration field while the timer is “active.” This is one possible way to avoid confusion when looking at a record and wondering whether the timer is active or not. :slightly_smiling_face: It’s not exactly a status indicator, but it’s a first start. I’ve got some other ideas that I plan on adding to later updates, including optional status indicators (text/emojis), and an alternate method of starting/stopping the timer using automation so that the blocks sidebar doesn’t need to be involved.

Here’s the script.

32 Replies 32

This is fantastic!! Great job, @Justin_Barrett!! :grinning: :raised_hands: :clap:

Thanks for sharing this script! Storing the timer history as json in a text field is an awesome idea. One reason why I didn’t like the Time Tracker block was because there is no history.

Michael_Andrew
8 - Airtable Astronomer
8 - Airtable Astronomer

Pretty cool. I set up a little color scheme so that when stopped it’s red (Duration is not empty) and green when started (Duration empty). The only issue is the start. You have to click that first time to get this started. Not sure how we could indicate that the button has never been pushed before.

image

I recall seeing a comment by @Bill.French about storing data in text fields as JSON, so he deserves some credit for inspiring that approach.

Using color conditions is an awesome idea! To add one that will trigger for un-timed records, add another color option above the {Duration} field check that sets a color when the data field is empty. It’s only going to be empty before the timer is run once, so that condition will only be true once. After that, the others will take over.

Caroline_Riteno
6 - Interface Innovator
6 - Interface Innovator

Ya’ll are INCREDIBLE. Thank you SO MUCH for your help. I love the idea of the conditional formatting with the colors, too! I was so anxious to ask for help but you all have been INCREDIBLE!

I agree @Justin_Barrett, about the block opening and being annoying, so keep me in the loop.

I love that your solution includes making the duration block blank while the timer is running, because I couldn’t figure out what was on! Ha! :slightly_smiling_face:

PS I wrote my own mini-script for an automation yesterday to delete a record once it moves. I’m learning! :slightly_smiling_face: Seeing all of your example that solve real-world problems for me has helped me understand more about java script. This community is awesome!

@Justin_Barrett …quick question.
If i have the time tracker block set up to also go to the same duration field, could i use either/or to start? Sometimes I need to do the quick search to start a timer and sometimes i want to click from the task base. If not, no biggie, I was just curious. :slightly_smiling_face:

Using color conditions is an awesome idea! To add one that will trigger for un-timed records, add another color option above the {Duration} field check that sets a color when the data field is empty. It’s only going to be empty before the timer is run once, so that condition will only be true once. After that, the others will take over.

Ah, smart. Works great.

image

Unfortunately not. The way I’m tracking time has no connection to the Time Tracker block, and there’s no way I can interface with that block to stop a timer that has been started with it.

However, that does give me an idea for an update to the script, which would allow you to use either system on the same record and keep everything in sync. The only caveat is that it would only work provided that you start and stop the timer with the same system each time. For example, you could start and stop the timer with my script, then start and stop it with the Time Tracker block, then go back to my script for the next run, and everything would work. What wouldn’t work is to start with one and stop with the other. That’s not technically possible.

That’s kinda what i was thinking would happen. I could start/stop with the time block or i could start/stop with the script button. :slightly_smiling_face: I’d just prefer, at the end of the day, to have the duration be in one field for tracking purposes. :slightly_smiling_face:

No rush, really. Both of your scripts have been incredibly helpful already!