Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Thursday, January 1, 2015

101 Google Apps Scripts Basics


.

101 Google Apps Script Basics - Your first script

The steps below show how to build and run a simple standalone script that creates a Google Doc and emails you a link.

1. Visit script.google.com to open the script editor.

(You'll need to be signed in to your Google account.) If this is the first time you've been to script.google.com, you'll be redirected to a page that introduces Apps Script. Click Start Scripting to proceed to the script editor.

2. Create Project

A welcome screen will ask what kind of script you want to create. Click Blank Project or Close.

3. Edit codes

Delete any code in the script editor and paste in the code below.
function createAndSendDocument() {
  // Create a new Google Doc named 'Hello, world!'
  var doc = DocumentApp.create('Hello, world!');
  // Access the body of the document, then add a paragraph.
  doc.getBody().appendParagraph('This document was created by Google Apps Script.');
  // Get the URL of the document.
  var url = doc.getUrl();
  // Get the email address of the active user - that's you.
  var email = Session.getActiveUser().getEmail();
  // Get the name of the document to use as an email subject line.
  var subject = doc.getName();
  // Append a new string to the "url" variable to use as an email body.
  var body = 'Link to your doc: ' + url;
  // Send yourself an email with a link to the document.
  GmailApp.sendEmail(email, subject, body);
}

4. Run

REFERENCE:



.
2015-01

No comments:

Post a Comment