Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Re: Record timer script

5290 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
Paul_Warren
8 - Airtable Astronomer
8 - Airtable Astronomer

May I ask a silly question? What do you use a timer in Airtable for most often?

I love learning new applications for Aitable, but the timer seemed like more of a gimmick to me than useful. That must be false based on this thorough and intelligent conversation. Now I feel like I’m missing something super cool.

Thanks!!

At the moment, the only thing I use it for is tracking the time I work on client projects. My gut says that’s the most common use of it, but I’m sure there are other uses I haven’t thought of.

Hey! Ran into a snag! I accidentally have left my timer on overnight (more than once…ADHD is fun!) and I can’t find a way to edit it. When using the time tracker block, I would just fix the time (Example: Just subtract 12 hours) but when I do that with yours, and then start the script again, it overrides my input with the Json record. Any ideas?

often some records are open for a month for me. (Example, I have one line item for “Client Management” that I use for the entire month for when clients call in to order or I have to adjust their back end of their subscription accounts, etc :slightly_smiling_face:

You can edit the JSON data directly if you wish. With the timer stopped, there should be an even number of values in the array, with each pair representing a single timing period. Each number represents the time when the button was pressed, down to the millisecond. It’s just a matter of doing the math to figure out how much to reduce the last number.

To take away 12 hours, it’s 12 hours x 60 minutes x 60 seconds x 1000 milliseconds, or 43200000. Subtract that from the last number in the sequence, then replace the last number with the new value. I just ran a quick test adding 12 hours, then taking it away again, and it works. If you want to confirm, and don’t mind adding a couple more seconds, you can start the timer briefly, then stop it again, and there should be 12 fewer hours in the duration field.

@Caroline_Ritenour I’m planning to add an option to the script (how soon, I have no idea, because my schedule is quite full at the moment) to allow for the user to review the most recent tracked time before saving it, in case adjustments need to be made. It’ll have a more user-friendly interface, and won’t require any mathematical gymnastics to get the job done. :slightly_smiling_face: I’ll post an update here once that revision is complete.

This Justin. This looks amazing.
The standard Timer Block is a bit clunky to use.
I plan on using it for Time Tracking my tasks - what gets measures gets managed!

Welcome to the community, @Amit_Patel1! :grinning_face_with_big_eyes: Glad you like it! Keep an eye on this space, as I’ve got an alternate version that I plan on sharing soon that works via automation so that the sidebar won’t open when it’s triggered.

Jon_Rosen
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi Justin. This was very useful. Thanks for posting it here. I have a question. Have you found a way to run the script without the application area opening? Thanks.

Short answer: Yes…sorta. Instead of triggering it via a button, I chose to set it up as an automation—more accurately two automations—triggered by a single-select. I still have plans (that have been floating around my noggin for ages) to document the setup in more detail, but using automations is the only way to keep the app sidebar closed.

Jon_Rosen
5 - Automation Enthusiast
5 - Automation Enthusiast

That’s an interesting idea. I tried running the same script as an automation, but it failed for me. I suspect that it’s losing focus and isn’t “in” any record when it runs, but you must know how to get around that.