Help

Re: Record timer script

3892 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.

31 Replies 31

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
7 - App Architect
7 - App Architect

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!

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.