-2
myFunction(e){
var Name = e.values[1];
DocumentApp.create("Test");
DocumentApp.appendParagraph("hello" + Name);
DocumentApp.saveAndClose;
}

This is how simple I want it. "Name" is pulled from a sheet that is generated from a form and "Name" is inputted after form generates its data, upon edit


  1. I am brand new to this. I mimicked the auto responder for when you get a form response, and "myFunction(e)" was name of function.
  2. I would think bound to spreadsheet. Path from beginning to end: input data to form>collect data on spreadsheet>edit spreadsheet, add more data>create simple letter using most of data collected. Sample letter

DocumentApp....appendParagragh("dear " + Name + "\n\n I like your " + Product + ". Are you interested in selling?").

There is an error related to "var Name = e.values[1];"

"TypeError: Cannot read property "values" from undefined. (line 2, file "Code")"

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Ive generated auto response emails from form data. – Richard Fullem Jan 28 '18 at 00:38
  • Ive created new doc using script. Im having trouble merging the 2 is all – Richard Fullem Jan 28 '18 at 00:39
  • 1
    Where is your script, bounded to a doc or spreadsheet or stand-alone? How are you calling your function? What is the value of `e`? If you are getting an error add it textually. – Rubén Jan 28 '18 at 02:55
  • 1. I am brand new to this. I mimicked the auto responder for when you get a form response, and "myFunction(e)" was name of function. 2. I would think bound to spreadsheet. Path from beginning to end: input data to form>collect data on spreadsheet>edit spreadsheet, add more data>create simple letter using most of data collected. Sample letter DocumentApp....appendParagragh("dear " + Name + "\n\n I like your " + Product + ". Are you interested in selling?"). There is an error related to "var Name = e.values[1];" "TypeError: Cannot read property "values" from undefined. (line 2, file "Code")" – Richard Fullem Jan 28 '18 at 05:58
  • It looks that you are trying to do a "mail merge" app and asking about the whole flow makes the question too broad for this site. Try to make your question to be specific about one operation or programming issue. If you need help with several flow parts / issues post each one on separate questions. – Rubén Jan 29 '18 at 17:23

1 Answers1

0

The error that you are getting occurred because you tried to run your function using the Run button on the Google Apps Script editor as the function has e as parameter but it only gets an object automatically when it's called from a trigger.

A couple of related Q&A


In order to get a value from a spreadsheet by using Google Apps Script we could use Class SpreadsheetApp. Example

The following script works on a bounded to spreadsheet script project.

function getName(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Sheet1');
  var range = sheet.getRange('A1');
  var name = range.getValue();
  Logger.log(name);
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
  • What does logger.log do? And will that A1 change on edit? – Richard Fullem Jan 29 '18 at 03:13
  • @RichardFullem Reggarding Logger.log see https://developers.google.com/apps-script/guides/support/troubleshooting#logging_custom_messages – Rubén Jan 29 '18 at 03:22
  • Regarding the second question please checkout https://developers.google.com/apps-script/guides/sheets – Rubén Jan 29 '18 at 03:26
  • So if I just put .getrange('A') and set my trigger to upon edit would that use the new data added in column A? – Richard Fullem Jan 29 '18 at 17:07
  • @RichardFullem 'A' is not a valid cell/range reference. – Rubén Jan 29 '18 at 17:09
  • TypeError: Cannot call method "getRange" of null. (line 4, file "Code")...very confused – Richard Fullem Jan 29 '18 at 17:27
  • @RichardFullem Assuming that you are using the code in my answer on a bounded to spreadsheet script project, your spreadsheet should have a sheet named 'Sheet1' in order to work. Maybe you should have to read https://developers.google.com/apps-script/guides/sheets – Rubén Jan 29 '18 at 17:32
  • Fixed that problem now I just need to be able to change a1 to a2 or a-cell that I edit/change(automatically). The way i want it set up is: where i start with inputing data a1 then a2 then a3 but know that if any complications with a row that i can skip and comeback. – Richard Fullem Jan 29 '18 at 17:57
  • myFunction(e){name = e.value[1]} why does this work when I do auto response mail but not on creating a document? – Richard Fullem Jan 29 '18 at 18:00
  • @RichardFullem I explained that on the first paragraph of my answer. – Rubén Jan 29 '18 at 18:04
  • @RichardFullem I added a couple of related Q&A about the same error. – Rubén Jan 29 '18 at 18:15
  • Sry im sick and not comprehending very well today. I do appreciate putting in the time to help me. – Richard Fullem Jan 29 '18 at 19:15