Help

Time Tracker Block + Button to start?

Topic Labels: Extensions
5498 20
cancel
Showing results for 
Search instead for 
Did you mean: 
Caroline_Riteno
6 - Interface Innovator
6 - Interface Innovator

Hello everyone.
I have built a robust task management system in airtable. I run my own business and i wanted to track the time it takes me at various tasks so that when I am ready to hire out/hire intern etc I have an idea of what i’m spending the most time on. I have started using the time tracker block to accomplish this, but i’d love to be able to add BUTTON right next to the task in order to accomplish this. I don’t have scripting experience but I was curious if this was possible? The fact that I cant just be working down my task list and say “start time tracker” drives me crazy and I was hoping to just integrate. Thanks!

20 Replies 20

This is great if I was adding a new task each time. Thank you!
I’m looking for a way to have a button that says “start time tracker” and it will track the time. My task system is robust and has pre-programmed tasks, etc . Will this work for that?

HAHA! Thanks! :slightly_smiling_face: I appreciate it.

My previous script uses a new record for each set of time on task.

Here is a new script that will work with tracking time in a duration field.
You will need to have three fields:

  • a date/time field to store the starting date/time (set this field name in the script)
  • a duration field to store the running duration (set this field name in the script)
  • a button field that calls the script
let startFieldName = "StartTime"
let durationFieldName = "Duration"

let table = base.getTable(cursor.activeTableId);
let record = await input.recordAsync("Pick a record", table);

const now = new Date();
const startTimeString = record.getCellValue(startFieldName);
if (!startTimeString) {
    table.updateRecordAsync(record, {[startFieldName]: now.toISOString()})
} else {
    const startTime = Date.parse(startTimeString);
    const newDuration = (now - startTime) / 1000
    const oldDuration = record.getCellValue(durationFieldName)
    table.updateRecordAsync(record, {
        [durationFieldName]: oldDuration + newDuration,
        [startFieldName]: null,
    })
}

@Justin_Barrett I hope you don’t mind me sharing how I track time. I hope you’ll share your method as well. There are many ways to do things in code, and I enjoy seeing different ways of solving the same problems.

I don’t mind at all! The method I came up with is similar to yours to some extent, but quite different in others. I don’t actually use this system with my own time tracking, but I’m tempted to start now that I’ve been playing with it. :slightly_smiling_face: I’ll probably have my version (at least v1 of my version) ready to share either later today or tomorrow.

@kuovonne
Thanks! I loaded this in this morning, and when I click the button, it opens the script block and I have to hit run …is that right? I’m wondering if I didn’t set something up correctly.

Also, once I hit “Stop” on the script block, the duration does not automatically update to the new time, until I hit the time tracker button again. Weird.

Alsoooo… I’m new at scripting here so I don’t understand why “Date” is purple in my script. See screenshot below. (I just made my table fields match yours so that’s a non-issue in my script, but not sure why “Date” is showing up purple)…I’m getting a red error around line 7 -screenshot below.

Appreciate your help!

image

I’m looking forward to your version, too!

@Caroline_Ritenour This scripting solution works differently from the Time Tracker block.

Although you can click the run button in the Scripting block, this solution is not designed to work that way.

You need to create a Button field to run the script. Then click the button field to start and stop the time. You also will not see a running timer because Scripting block cannot do that. The {duration} also will not update until you click the button a second time to indicate that you are done working on the task.

Don’t worry about the color coding and “error”. The purple color is just how the editor color codes that type of object. The “error” that looks like it is on line 7 is actually referring to the wavy red underlines on line 13; The editor doesn’t recognize that it is possible to do arithmetic with date; however, the code runs just fine. The Scripting block editor is a bit overzealous in marking errors and puts wavy red underlines on things that aren’t actually errors.

@kuovonne
AHHHH I see the “error in my ways” :slightly_smiling_face: I was clicking ‘run’ on the script itself after pushing the button (because it didn’t say the script was running :slightly_smiling_face: GOT IT! Thank you!

I just posted a new thread with details about my timer script. I shared it separately instead of pasting the script here mainly because I plan on updating it a few more times with more features that came to mind during development. Mine also uses a button field to both start and stop the “timer,” but uses a different method of storing the timing data, which allowed me to implement an idea that I mentioned earlier in this thread (emphasis added):

Here’s a link to the new thread: