Academy ↓
Hey there stranger!
Sign up to get access.
Now Do It Every Damn Day - Learn to Code in Google Sheets Part 5
About this Tutorial
Sheet Resources
Video Transcript
0:08 In other parts of programming is called chron jobs. Chron like a time I think a Greek word for time. So we, in Google Script and Google Sheets, we use triggers and these can trigger or start a script sort of at any particular time of day or time of week.
0:29 We have lots of options, but I'm gonna show you one, one specific type of trigger. So first off, let's go back to our app script, open it up and the function.
0:41 We wanna run this copy sales data to sales log is what we wanna trigger. Over on our left side of our ops script, we have five sections.
0:50 We've been using the editor section so far. There's also an overview. I use that very rarely. And underneath the editor is triggers.
0:58 So let's look at that triggers over here. On the bottom right is ad trigger. We click that we choose which function to run.
1:06 If it's not already chosen for us, we already see it's copy sales, data log, choose which deployment. Always gonna be head from spreadsheet is not the event source.
1:16 We have to select this event source. Time driven here, we have lots of options but what we wanna do is Daytimer cuz we wanna run it between at some point in the day, every single day.
1:30 And what Daytimer allows you to do is select an hour out of the day. So I usually choose something like three to 4:00 AM and we hit save.
1:41 Now what's it's gonna do is it will start at some point between that hour and then every time after that it'll wait 24 hours and run again.
1:54 So this is gonna run every 24 hours. Once it starts running, you can only pick a spec, a specific sort of hour.
2:01 You can't pick at 5 0 2. At 5 0 3 you can say between 5:00 AM and 6:00 AM. But once it starts, it will then take 24 hours to start again.
2:15 The lovely thing about triggers is that they run on Google servers. You do not have to spin up a server, don't have to know html, you don't have to know css, you don't have to run a server.
2:26 We can run this code from Google servers as much as we want. We can also have more than one trigger.
2:33 So we can run it maybe twice a day, three times a day, four times a day or four times a week or at specific times.
2:40 You can see all of the triggers that are available, at least the time driven ones. Here you have specific ti date and time, which is one specific time and date.
2:50 You have minutes, hours, days, weeks and months. One interesting thing about this is that If you go and copy this sheet in particular, so out of all these videos, if you've been copying the sheets as we go along and seeing all the steps, you'll be able to open app script and see the script.
3:11 But you will not be able to see my trigger. And this is even true on sheets that you share with other people.
3:18 So if you and your boss or you and your coworker or you and your employees are sharing a sheet, one of you creates a trigger, the other people cannot see that trigger, but they can be affected by it.
3:30 So if somebody writes a script and I create a trigger, this trigger will trigger that script to run even if someone else created the script, but they won't be able to see my trigger.
3:44 So that is one downfall of Google Script triggers here. Another restriction of app script that might be interesting based on triggers is that an app script can only run for 30 seconds.
4:01 It will time out after that. So you can't really time things like Pomodoro like 25 minutes, you can't time hours.
4:09 There's some limitations to app script and there are actually a lot more, but you don't really run into them very often.
4:17 One more limitation before we end this video is that triggers, if I create a script that triggers an edit, oned scripts won't be triggered, meaning a person has to edit the sheet.
4:34 So a triggered script will not trigger an oned script to run. I hope that makes sense. Essentially an oned must only be user is editing a sheet so it won't be triggered by triggers.
4:52 In the next video I'll actually go into more different types of triggers, but I just wanted to get this one to you and make sure you understood triggers cuz it's probably one of the most important parts of automating things and creating the scripts is that you can run them automatically.
5:08 This is truly automatic. Once you start it, it will run forever until you delete that trigger. Let me show you how to delete that trigger.
5:16 We go to edit, actually we don't even go to edit. We go to the three buttons here, delete trigger. That's how we can delete forever this trigger.
5:25 So again, I can even save this trigger and you're gonna copy this page and won't be able to see the trigger so that I create.
5:30 So I just deleted it. Thanks for watching. See the next video where we go into a lot more concepts and I share with you more opportunities of what can happen in app Script.
5:40 I hope you've been enjoying learning to code in app.
Courses
Why Code in Google Sheets? - Learn to Code in Google Sheets Part 1
Tips to Navigating Thousands of Lines of Code In Apps Script
How to Write a Function - Learn to Code in Google Sheets Part 2
From Sheet to Script And Back Again - Learn to Code In Google Sheets Part 3
Copy That, From One Sheet to Another - Learn to Code in Google Sheets Part 4
Now Do It Every Damn Day - Learn to Code in Google Sheets Part 5
Wrap Your Mind Around This - Learn to Code in Google Sheets Part 6
Write Your First Script
00:08:31
How to Record Macros
00:06:20
How to Edit a Macro
00:08:22
How to Trigger Macros Daily
00:06:58
Automatically Uncheck A Daily Checklist
How do I reference a different spreadsheet in Apps Script?