Help

Re: Time Tracker Block + Button to start?

4157 6
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

While the Time Tracker block can’t currently be started this way, this sounds like a great addition to the button field’s options. I suggest starting a new thread (after searching for an existing one) in the #show-and-tell:product-suggestions category to propose adding this to the button field.

In the meantime, what you want could be done with the help of a script in the scripting block, which could be triggered by a button field. It would take some time to set up (no pun intended), but I can envision something where you click the button once to start it, click it later to stop it and store the elapsed time in a duration field, maybe click it later to restart if needed, click again to stop and store the new time added to the former time, and so on. Would something like that be useful?

Yes! That’s what I was trying to figure out. I don’t have scripting experience, at all, but I started looking into it yesterday and today and i’m getting an idea of how it works.

I’m not even too concerned with clicking the button to STOP it, i’d be happy to use the block to stop ,but i’d love to just be able to click the button to start time.

Just to be clear, you wouldn’t be able to use the time tracker block to stop it. The time tracker block stores data internally to tell when its tracking is started and stopped, and it even persists if Airtable is closed. However, the scripting block can’t access any other block’s properties, so you couldn’t start it with the script and stop it with the time tracker block. Because data in a scripting block’s code can’t persist between uses, the system I was thinking of building would use an extra field in the table to store data related to the start and stop times, and do the appropriate calculation each time it’s run.

Thanks!

Would you be able to help me write the script? I experimented this morning with a little bit of scripting but I really have no clue what I’m doing.

I’d be happy to help. In fact, I was already planning on putting some time into it based on this discussion, because it seems like an interesting problem. I don’t think it’ll take long, but I’ve also got to carefully arrange that development time around other obligations. Ideally I can have it done within a week, but I can’t promise anything.

Caroline_Riteno
6 - Interface Innovator
6 - Interface Innovator

Oh my gosh!!! That would be fantastic!
I’m not in a rush, so a week or two would be fine. Thank you!

Hey! I just thought i’d reach out and touch base and see where you are at! :slightly_smiling_face:

I track my time for some projects in an Airtable base. I have it setup so that when I start a new task, I create a new record and click a “start” button. When the task is over, I click a “stop” button. Both buttons run scripts that set the current time in a date/time field. I then have other fields to calculate the duration. The two scripts are identical, except for the name of the field at the top.

const dateTimeFieldName = "StartDateTime"

const table = base.getTable(cursor.activeTableId)
const record = await input.recordAsync("Pick a record", table)
const time = new Date()
const writeString = time.toISOString()
table.updateRecordAsync(record, {[dateTimeFieldName]: writeString})
output.markdown(`Set {${dateTimeFieldName}} to ${writeString}`)

Here is a version that can be used with a single start/stop button:

const startDateTimeFieldName = "StartDateTime"
const endDateTimeFieldName = "EndDateTime"

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

if (record.getCellValue(startDateTimeFieldName)) {
    table.updateRecordAsync(record, {[endDateTimeFieldName]: new Date().toISOString()})
} else {
    table.updateRecordAsync(record, {[startDateTimeFieldName]: new Date().toISOString()})
}

Your timing is great (pun fully intended)! :grinning_face_with_big_eyes: I worked on this yesterday, and got the basic version working well. I still want to polish it a bit before sharing it, though, but it should be ready by some time next week at the latest.