How to Run a Function Automatically

Share with others...

You have created a function that performs some amazing stuff using Google Apps Script, but the functions that you create run manually when you click a button or a menu item from your Spreadsheet GUI. Since we are talking about automation, we need to run these functions automatically even when the spreadsheet is not open. Luckily, Google provides free time-driven triggers that execute functions automatically even if the spreadsheet itself is not open!

Time-driven triggers can be created in 2 ways, namely from the triggers interface and in code.

Triggers Interface Method:

To access the triggers interface, you need to open the Apps Script editor from the Extensions menu of your spreadsheet. Navigate to the Triggers page by clicking on the clock icon from the left sidebar. This opens the list of active triggers (if any). Here, please fill up the form as follows:

  1. Choose which function to run: choose your function (getGmailEmails() is my function from my previous post).
  2. Choose which deployment should run: Head.
  3. Select event source: Time-Driven.
  4. Select type of time based trigger: select any type (like Day Timer).
  5. Select time of day: choose your time interval.

You may repeat these steps again for whatever time or whatever function you would like the trigger to run on. I advise not to create triggers that less than 10 minutes.

Below is a screen recording which shows how to create time-driven triggers:

Triggers from Code Method:

I will cover how triggers can be created in code in the next post update.

One thought on “How to Run a Function Automatically

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top