3 Impressive Google Docs Scripts to Automate Your Documents

function myFunction() {
  // Display a dialog box for each field you need information for.
  
  var ui = DocumentApp.getUi();
  //var response = ui.prompt('Enter Name', 'Enter sales person's name', ui.ButtonSet.OK);
  var nameResponse = ui.prompt('Enter sales persons name');
  var client1Response = ui.prompt('Enter client 1');
  var sales1Response = ui.prompt('Enter sales 1');
  var client2Response = ui.prompt('Enter client 2');
  var sales2Response = ui.prompt('Enter sales 2');
  var client3Response = ui.prompt('Enter client 3');
  var sales3Response = ui.prompt('Enter sales 3');
  var commissionResponse = ui.prompt('Enter commission');
  var date = new Date();
    
  //Make a copy of the template file
  var documentId = DriveApp.getFileById('<your-template-id>').makeCopy().getId();
      
  //Rename the copied file
  DriveApp.getFileById(documentId).setName(nameResponse.getResponseText() +
 date + ' Sales Report');  
      
  //Get the document body as a variable
  var body = DocumentApp.openById(documentId).getBody();
    
  //Insert the entries into the document
  body.replaceText('##name##', nameResponse.getResponseText());
  body.replaceText('##client1##', client1Response.getResponseText());
  body.replaceText('##sales1##', sales1Response.getResponseText()); 
  body.replaceText('##client2##', client2Response.getResponseText());
  body.replaceText('##sales2##', sales2Response.getResponseText());  
  body.replaceText('##client3##', client3Response.getResponseText());
  body.replaceText('##sales3##', sales3Response.getResponseText());
  body.replaceText('##commission##', commissionResponse.getResponseText());   
}

Replace the document ID code in the script above with the document ID of the template document.

You’ll find this embedded in the URL when you’re editing the template document.

computer science computer science computer science computer science computer science

document id

computer science computer science computer science computer science computer science

In the Google Script editor window, click the disk icon to save the script.

Next, click on the run icon to test that it works.

When you run the script for the first time, you may need to approve permissions for your Google Account to run the script.

Back in the template document, you’ll see the prompt windows pop up one after the other. Fill in the fields with the data you want to go into the document.computer science computer science computer science computer science computer science

google doc prompts

When you’re done, the script will create a new document in your Google Drive root folder with all of the information you’ve entered filled in.

Prev2 of 7Next

Leave a Reply

Your email address will not be published. Required fields are marked *