Members-only tutorial

Watch the video and get the practice sheet with membership.

Unlock tutorials

Now Do It Every Damn Day - Learn to Code in Google Sheets Part 5

About this Tutorial

Now that we have a script that we wanna run every day, how do we run this? This is a key part of programming. It's like Cron Jobs in Apps Script

Video Transcript

<div>0:00 Now that we have a script that we wanna run every day, how do we run this? This is a key part of programming.<br>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.<br>0:29 We have lots of options, but I'm gonna show you one, one specific type of trigger . Learn to Code in Google Sheets, For Programmers | For Advanced Google Sheet Users Insert Row Daily Automatically

So first off, let's go back to our app script , open it up and the function .<br>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.<br>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.<br>0:58 So let's look at that triggers over here. On the bottom right is ad trigger . Learn to Code in Google Sheets, For Programmers | For Advanced Google Sheet Users Quick Follow Up Email

We click that we choose which function to run.<br>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.<br>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.<br>1:30 And what Daytimer allows you to do is select an hour out of the day. Learn to Code in Google Sheets, For Programmers | For Advanced Google Sheet Users Insert Row Daily Automatically

So I usually choose something like three to 4:00 AM and we hit save.<br>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.<br>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.<br>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.<br>2:15 The lovely thing about triggers is that they run on Google servers. Email Yourself a Cell from a Google Sheet, Every Day Copy Date to Next Cell Automatically

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.<br>2:26 We can run this code from Google servers as much as we want. We can also have more than one trigger .<br>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.<br>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.<br>2:50 You have minutes, hours, days, weeks and months. Learn to Code in Google Sheets, For Programmers | For Advanced Google Sheet Users Automatic Email Report from Google Sheets

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.<br>3:11 But you will not be able to see my trigger . When did you learn the secrets of Google Sheets? | Sheet Talking Episode 8 Esa Click Checkbox to Copy to Tab in Google Sheets

And this is even true on sheets that you share with other people.<br>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.<br>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 .<br>3:44 So that is one downfall of Google Script triggers here. Simply Email Yourself From a Google Sheet Expire A Shared Public Link in Google Sheets

Another restriction of app script that might be interesting based on triggers is that an app script can only run for 30 seconds.<br>4:01 It will time out after that. When did you learn the secrets of Google Sheets? | Sheet Talking Episode 8 Esa

So you can't really time things like Pomodoro like 25 minutes, you can't time hours.<br>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.<br>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.<br>4:34 So a triggered script will not trigger an oned script to run. I hope that makes sense. When did you learn the secrets of Google Sheets? | Sheet Talking Episode 8 Esa How to Stop onEdit Automation in Google Sheets

Essentially an oned must only be user is editing a sheet so it won't be triggered by triggers.<br>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.<br>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 .<br>5:16 We go to edit, actually we don't even go to edit. What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users Automatic Calculations How to Stop onEdit Automation in Google Sheets

We go to the three buttons here, delete trigger . That's how we can delete forever this trigger .<br>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.<br>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 .<br>5:40 I hope you've been enjoying learning to code in app.</div> What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users How to Prevent Delete Tab