0

I am trying to create a script that will use a submitted Google Form to create an agenda for a meeting. I used the script "Employee of the Week Award" as a starter but my total inexperience with coding has me stumped.

I have created a googde doc agenda template with key place holders matching the data I'm asking for in the google form (thus the headers of the columns in my google spreadsheet). The goal is when someone submits a form describing the agenda items for their meeting, this script grabs that data and uses the google doc agenda template to create an agenda for their meeting.

Here's the script I've edited:

// Global variables 
    var docTemplate = "1-4ELCpEGvrtnprnBYoLapwASK6TYmt3YpY0BkBKICrM";  
    var docName     = "Agenda";

function onFormSubmit(e) { // add an onsubmit trigger
// Meeting name and date values come from the spreadsheet form
   var meeting_name     = e.values[1];
   var date             = e.values[2];
// Get document template, copy it as a new temp doc, and save the Doc’s id
   var copyId = DocsList.getFileById(docTemplate)
            .makeCopy(docName+' for '+Meeting_Name)
            .getId();
// Open the temporary document
   var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
   var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,  
   copyBody.replaceText('keyMeeting_Name', Meeting_Name); 
   copyBody.replaceText('keyDate', Date);
   var Agenda_Item_1 = e.values[3]
   var Item_1_Time   = e.values[4] 
   var Agenda_Item_2 = e.values[5] 
   var Item_2_Time   = e.values[6] 
   var Agenda_Item_3 = e.values[7] 
   var Item_3_Time   = e.values[8] 
   copyBody.replaceText('keyAgenda_Item_1', Agenda_Item_1);
   copyBody.replaceText('keyItem_1_Time', Item_1_Time);
   copyBody.replaceText('keyAgenda_Item_2', Agenda_Item_2);
   copyBody.replaceText('keyItem_2_Time', Item_2_Time);
   copyBody.replaceText('keyAgenda_Item_3', Agenda_Item_3);
   copyBody.replaceText('keyItem_3_Time', Item_3_Time);
// Save and close the temporary document
   copyDoc.saveAndClose();
}

When I run it, I get TypeError: Cannot read property "values" from undefined (line 7). I'm assuming that error would be true for all the subsequent e.values lines.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
user1873595
  • 1
  • 1
  • 1
  • 3
  • Does this answer your question? [How can I test a trigger function in GAS?](https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas) – Rubén Jun 17 '20 at 02:38

1 Answers1

2

If you run this function manually, e will be undefined. You will need to install a trigger to run onFormSubmit() when someone submits a form. Instructions on that are here under the heading "Using Container-Specific Installable Triggers". With the trigger installed, the script will run when someone submits a form, and various aspects of the 'form submit' event can then be found in the object assigned to e as described here in the table "Spreadsheet Form Submit Events". Specifically, e.values will be an array containing values the user has entered in the form.

Joel
  • 95
  • 9