Guest User

Untitled

a guest
Jul 30th, 2013
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. /*This is the document template I created*/
  2. var docTemplate = "1yw00mmVcRB8kEFYz4tyAcD1WiNx1tjKfMYrikMSuOHg"
  3. /*Document name for naming the PDF at the end*/
  4. var docName = "Fault Report";
  5. /*The email address the forms get emailed to*/
  6. var email_address = "[email protected]";
  7. /*This function is linked as a trigger from the form page - onFormSubmit.*/
  8. function onFormSubmit(e) {
  9. /*I set the variable branch to the first value in the form - in this case, branch*/
  10. var branch = e.values[1];
  11. var received = e.values[2];
  12. var company = e.values[3];
  13. var account = e.values[4];
  14. var invoice = e.values[5];
  15. var name = e.values[6];
  16. var phone = e.values[7];
  17. var address = e.values[8];
  18. var desc = e.values[9];
  19. var part = e.values[10];
  20. var serial = e.values[11];
  21. var date = e.values[12];
  22. var fault = e.values[13];
  23. var info = e.values[14];
  24. var action = e.values[15];
  25. /*I make a copy of the document temporarily so that I can edit it*/
  26. var copyId = DocsList.getFileById(docTemplate).makeCopy(docName+' for '+company).getId();
  27. /*Open copied document*/
  28. var copyDoc = DocumentApp.openById(copyId);
  29. /*Grab the body of the document*/
  30. var copyBody = copyDoc.getActiveSection();
  31. /*Replacing my placeholder text with my variables from the form submission*/
  32. copyBody.replaceText('keyBranch', branch);
  33. copyBody.replaceText('keyReceive', received);
  34. copyBody.replaceText('keyCompany', company);
  35. copyBody.replaceText('keyAccount', account);
  36. copyBody.replaceText('keyInvoice', invoice);
  37. copyBody.replaceText('keyContact',name);
  38. copyBody.replaceText('keyPhone', phone);
  39. copyBody.replaceText('keyAddress', address);
  40. copyBody.replaceText('keyDesc', desc);
  41. copyBody.replaceText('keySerial', serial);
  42. copyBody.replaceText('keyPart', part);
  43. copyBody.replaceText('keyDate', date);
  44. copyBody.replaceText('keyFault',fault);
  45. copyBody.replaceText('keyInfo', info);
  46. copyBody.replaceText('keyAction', action);
  47. copyDoc.saveAndClose();
  48. /*Subject/body for the email*/
  49. var subject = 'Fault report for '+company;
  50. var body = "Here is the fault report for " + company + "";
  51. var faultreport = DocsList.getFileById(copyId).getAs("application/pdf");
  52. /*Send email to my email address stated above, with a PDF attachment of my fault report.*/
  53. MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: faultreport});
  54. /*Delete temporary document so I don't get a drive full of fault reports*/
  55. DocsList.getFileById(copyId).setTrashed(true);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment