Book Image

Learning Google Apps Script

By : Ramalingam Ganapathy
Book Image

Learning Google Apps Script

By: Ramalingam Ganapathy

Overview of this book

Google Apps Script is a cloud-based scripting language based on JavaScript to customize and automate Google applications. Apps Script makes it easy to create and publish add-ons in an online store for Google Sheets, Docs, and Forms. It serves as one single platform to build, code, and ultimately share your App on the Web store. This book begins by covering the basics of the Google application platform and goes on to empower you to automate most of the Google applications. You will learn the concepts of creating a menu, sending mails, building interactive web pages, and implementing all these techniques to develop an interactive Web page as a form to submit sheets You will be guided through all these tasks with plenty of screenshots and code snippets that will ensure your success in customizing and automating various Google applications This guide is an invaluable tutorial for beginners who intend to develop the skills to automate and customize Google applications
Table of Contents (16 chapters)
Learning Google Apps Script
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Building a Gmail Contact search application


Now, we will create an application to search existing contacts. This application is able to search and list your Gmail Contacts in Sheets. Create a new Sheet and rename Sheet1 to Contacts and set it up as shown in the following screenshot. Create a button and assign the function name searchContacts to it, as you learned in the previous chapter.

Create the searchContacts function as listed here:

function searchContacts(){

  var SheetContacts = SpreadsheetApp.getActiveSpreadsheet()
      .getSheetByName("Contacts");

  // Read input from cell A3 
  var searchCriteria = SheetContacts.getRange("A3").getValue();

  //  First 10 contacts.
  //  [You can change this limit, but advised to keep small.]
  var numOfContacts = 10;

  // Clear existing sheet data
  SheetContacts.getRange(7,1,numOfContacts,4).clear();

Here, clear is the Range object's method to clear everything including format and formula, in a range of cells. You can use the clear method of...