Google Apps Script Time Based Trigger Date and Time


Google Apps Script Time Based Trigger Date and Time

Google Apps Script provides the two types of triggers based on requirement.
  1.    Simple Trigger
  2.    Installable Triggers
Simple Trigger are used 6 reserved functions, when a user opens the spread sheet,forms, slides and docs, then we can use any one of thes
e reserved function to trigger the any thing. Actually we can manage the triggers in Programmatically and Manually

The 6 Reserved Triggers functions are

          1. onOpen(e) 
          2. onEdit(e) 
          3. onSelectionChange(e)
          4. onInstall(e)
          5. doGet(e) 
          6. doPost(e) 
Below is the simple triggers syntax

------------------------------onInstall-------------------------
function onInstall(e) {
  onInstall(e)
}
---------------------------------onOpen------------------------
function onOpen(e) {
  onOpen(e);
}
--------------------------------onEdit---------------------------
function onEdit(e) {
onEdit(e) 
}
-----------------------------------onOpen------------------------
function onOpen(e) {
  onOpen(e);
}
--------------------------------------------------------------------

below is the simple source code for simple triggers without reserved functions.

  /**
 * Trigger in Hours.
 */
function createHoursBasedAndDayBased() 
{
    // Trigger every 12 hours.
      ScriptApp.newTrigger('sendEmailsBasedOnTriggers')
         .timeBased()
         .everyHours(12)
         .create();

  // Trigger every THURSDAY at 12:00.
     ScriptApp.newTrigger('sendEmailsBasedOnTriggers')
         .timeBased()
         .onWeekDay(ScriptApp.WeekDay.THURSDAY)
         .atHour(12)
         .create();
 }

This is other function------------------------------------------------------->
/**
 * Sends emails with initialized values.
 */
function sendEmailsBasedOnTriggers() 
   {
    var emailAddress = "alltechgeekz@gmil.com"; // First column
    var message ="This is Trigger messged testing alltech geeks"]; // Second column
    var subject = 'Google Apps Script Time Based Trigger Date and Time';
    MailApp.sendEmail(emailAddress, subject, message);            
}







No comments: