Google Apps Script Document Creator

This script logs a greeting, creates a new Google Document with a timestamped title, and appends sample text to it while logging the document URL

Click to view script…
function myTestScript() {
  // Log a simple greeting message
  Logger.log("Hello, Google Apps Script!");

  // Get and log the active user's email address
  var userEmail = Session.getActiveUser().getEmail();
  Logger.log("Active user: " + userEmail);

  // Create a new Google Document with a unique name based on the current date and time
  var doc = DocumentApp.create("Test Document " + new Date());
  var body = doc.getBody();

  // Append some paragraphs to the document
  body.appendParagraph("This document was created by a test script in Google Apps Script.");
  body.appendParagraph("Active user email: " + userEmail);

  // Log the URL of the created document so you can easily open it
  Logger.log("Document created: " + doc.getUrl());
}