Answers for "google doc automation"

0

google doc automation

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());   
}
Posted by: Guest on October-19-2021

Browse Popular Code Answers by Language