Reader small image

You're reading from  Learning Google Apps Script

Product typeBook
Published inMar 2016
Publisher
ISBN-139781785882517
Edition1st Edition
Right arrow
Author (1)
Ramalingam Ganapathy
Ramalingam Ganapathy
author image
Ramalingam Ganapathy

Ramalingam Ganapathy is an independent computer software professional with more than 15 years of working experience of JavaScript and Google Apps Script. In 1985, he started his career as a digital electronic circuit designer and service engineer. Highly interested in reading technical books and building electronic projects, he is a detail-oriented and logical person. Since 2001, he has been freelancing with Elance and Upwork (formerly oDesk). He earned a good reputation on the Upwork portal, and most of his clients are satisfied.
Read more about Ramalingam Ganapathy

Right arrow

Chapter 5. Creating Google Calendar and Drive Applications

In the previous chapter, you learned how to create Forms programmatically using FormApp, ContentService, and HtmlService. Also, you learned how to use the doGet and doPost functions.

In this chapter, you will learn to:

  • Create Calendar events

  • Enable Google's advanced services

  • Create a few Drive applications

The CalendarApp class


The CalendarApp class provides direct access to Calendar's basic service. This service allows you to read and update your default as well as subscribed Calendars. Using GAS, you can create Calendar events, and invite your friends programmatically. You can even grab event details and populate them in Sheets.

Creating Calendar events from a simple description

You can create an event by just passing a description as an argument to the createEventFromDescription method of the CalendarApp class:

function createCalendarEventFromDescription(){
  CalendarApp.getDefaultCalendar()
    .createEventFromDescription('Team Meeting, Monday from 3 PM to 4 PM');
}

Creating simple Calendar events

You can also create events by specifying the title, start time, and end time:

function createCalendarEvents() {
    var title = "Title of the event";
    var startTime = new Date("October 21, 2015 21:00:00");
    var endTime = new Date("October 21, 2015 21:30:00");

    CalendarApp.getDefaultCalendar...

Enabling advanced Google services


Until now, you have been using GAS's basic services, such as GmailApp and ContactsApp. Now it is time to learn how to enable advanced services.

In this task, we are going to use a Calendar service, which is an advanced service, so we have to enable it before using it.

In the script editor, click on Resources, and then on Advanced Google services…, and a pop-up window will open:

In the Advanced Google Services pop-up window, all the GAS advanced services will be listed. Look for the Calendar API service, select the latest version (it is selected by default), and then enable it if is not already enabled. In the following screenshot, you can see that the Calendar API service is enabled:

Enabling advanced services only in scripts is not enough, you also need to enable it in the Google Developers Console, as indicated in the pop-up window. To do so, click on the link provided in the pop-window.

Then a new browser window or tab will open with popular APIs listed as...

The DriveApp class


This class allows you to create, search, and modify files and folders in your Drive.

For reference documentation on the DriveApp class, refer to the website: https://developers.google.com/apps-script/reference/drive/drive-app?hl=en.

Creating customized PDF files

Imagine that you need to create customized PDF files from the Sheet or external data. We can create PDF files from the HTML template. You simply need to format column headers and put some sample data in a new Sheet (AddressBook) as shown in the following screenshot:

Create the createPdfs function in the Code.gs file as listed here:

function createPdfs(){
  
  // 0 based column numbers
  const NAME = 0;
  const TITLE = 1;
  const COMPANY = 2;
  const ADDRESS = 3;
  const CITY = 4;
  const ZIP_PIN = 5;
  
  
  /* Get data from the sheet */
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();
  /*
   * Alternatively you can get data * from an external CSV file or anything else....

Summary


In this chapter, you learned about, and created, many useful real-world applications, including an event sync application. In the next chapter, you will learn how to create RSS/Atom readers and language translator applications.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Google Apps Script
Published in: Mar 2016Publisher: ISBN-13: 9781785882517
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ramalingam Ganapathy

Ramalingam Ganapathy is an independent computer software professional with more than 15 years of working experience of JavaScript and Google Apps Script. In 1985, he started his career as a digital electronic circuit designer and service engineer. Highly interested in reading technical books and building electronic projects, he is a detail-oriented and logical person. Since 2001, he has been freelancing with Elance and Upwork (formerly oDesk). He earned a good reputation on the Upwork portal, and most of his clients are satisfied.
Read more about Ramalingam Ganapathy