-2

Changed to DriveApp still have same challenges and error message

var docTemplate = "1nBZvKTMk5b82tiNvMqG3obmbY-lBIpodrIjvH-_sf7g";
var DocName = "SpringHillDisciplineReport";

// When Form Gets submitted
function onFormSubmit(e) {
//Get information from form and set as variables
  var email_address = "kroper@lexrich5.org, lweaver@lexrich5.org, eddavis@lexrich5.org";
  var studentname = e.values[2];
  var studentgrade = e.values[6];
  var date = e.values[5];
  var reportername = e.values[3];
  var locationofincident = e.values[8];
  var reasonforthereferral = e.values[9];
  var presentactiontakenbyadministrator = e.values[13];
  var infractioncode = e.values [10];
  var additionalcomments = e.values[14];

// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(DocName+' for '+ studentname)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
var copyBody = copyDoc.getActiveSection();

// Replace place holder keys,in our google doc template
copyBody.replaceText('keyStudentName', studentname);
copyBody.replaceText('keyDate', date);
copyBody.replaceText('keyStudentGrade', studentgrade);
copyBody.replaceText('keyLocationofIncident', locationofincident);
copyBody.replaceText('keyReasonfortheReferral',reasonforthereferral);
copyBody.replaceText('keyPresentActionTakenbyAdministrator',presentactiontakenbyadministrator);
copyBody.replaceText('keyAdditionalComments', additionalcomments);

// Save and close the temporary document
copyDoc.saveAndClose();

// Convert temporary document to PDF
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

// Attach PDF and send the email
var subject = "Discipline Referral Report";
var body = "Here is the Discipline Referral Report for " + studentname + "";
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf});

// Delete temp file
DriveApp.getFileById(copyId).setTrashed(true);
}
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Kim Roper
  • 1
  • 3
  • Can you post your code – Sachin K Apr 23 '15 at 13:45
  • possible duplicate of [How to update DocsList to DriveApp in my code](http://stackoverflow.com/questions/29777164/how-to-update-docslist-to-driveapp-in-my-code) – Zig Mandel Apr 23 '15 at 13:54
  • var docTemplate = "1nBZvKTMk5b82tiNvMqG3obmbY-lBIpodrIjvH-_sf7g"; var DocName = "SpringHillDisciplineReport"; // When Form Gets submitted function onFormSubmit(e) { //Get information from form and set as variables var email_address = "kroper@lexrich5.org, lweaver@lexrich5.org, eddavis@lexrich5.org"; var studentname = e.values[2]; THIS IS THE LINE WITH ERROR var studentgrade = e.values[6]; var date = e.values[5]; var reportername = e.values[3]; var locationofincident = e.values[8]; var reasonforthereferral = e.values[9]; var presentactiontakenbyadministrator = e.values[13]; – Kim Roper Apr 23 '15 at 14:38
  • It won't let me post entire code – Kim Roper Apr 23 '15 at 14:38
  • Also it has been working for over a year and I didn't change anything all of a sudden this morning stopped working – Kim Roper Apr 23 '15 at 14:40
  • it is not a duplicate of DocsList – Kim Roper Apr 23 '15 at 15:01
  • you need to edit the original post and include all your code there instead of trying to put it in comments. – ScampMichael Apr 23 '15 at 16:41
  • Ok I have fixed it to include the code I didn't change anything prior to it stopping to work today – Kim Roper Apr 23 '15 at 17:04
  • Take a look at [Getting TypeError in onFormSubmit trigger?](http://stackoverflow.com/a/17984695/1677912) – Mogsdad Apr 23 '15 at 18:34
  • 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

The DocsList service, which was deprecated in 2014, has been sunset and no longer functions. Users relying on DocsList should switch to DriveApp.

The two places in your code where you use DocsList should be updated for use with DriveApp

You cannot run this code from the code editor as it requires a submission from a form to work properly. You are receiving the error message that the value was undefined because there was no form submitted. The real problem is with DocsList

ScampMichael
  • 3,688
  • 2
  • 16
  • 23
  • Thanks I replaced that and am still getting the same error – Kim Roper Apr 23 '15 at 17:35
  • did you read the last paragraph of my post? your code cannot be run from the code editor.you must submit a form to get it to run properly. – ScampMichael Apr 23 '15 at 17:42
  • I did however I am not a programmer I had a form letter that was used for discipline that would merge with a google form and this script would run on form submit and it was working until yesterday when I started getting the error I just need some direction on what I can do to fix it at this point. – Kim Roper Apr 23 '15 at 17:45
  • the only way to test it is by submitting a form. Can you submit a dummy form and see if that works? – ScampMichael Apr 23 '15 at 17:49
  • Whew! glad to hear it. I thought you were going to have to invite me over to fix it. – ScampMichael Apr 23 '15 at 17:59