Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.15 KB | None | 0 0
  1. function sendEmail() {
  2.  
  3. //setup function
  4.  
  5. var ss = SpreadsheetApp.openById("1hKGe3F87qwMskKjzemilu8aH0V9mHyVJkH1lXLm8Feg");
  6. var ActiveSheet = ss.getSheetByName("FormCalculations");
  7.  
  8. var StartRow = 2;
  9. var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
  10. var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,118);
  11. var AllValues = WholeRange.getValues();
  12.  
  13. var message = "";
  14. //iterate loop
  15. for (i in AllValues) {
  16.  
  17. //set current row
  18. var CurrentRow = AllValues[i];
  19.  
  20. //define column to check if sent (starts from "0" not "1")
  21. var EmailSent = CurrentRow[104];
  22.  
  23. //if row has been sent, then continue to next iteration
  24. if (EmailSent == "sent")
  25. continue;
  26.  
  27. //set HTML template for information
  28. message +=
  29. "<font size='5'><p>CPI - Criteria Personality Inventory</p></font>" +
  30. "<p><b>New form submission recieved:</b></p>" +
  31. "<table cellpadding='10' cellspacing='0' border='0' bgcolor='#eeeeee' valign='top' style='width:90%; max-width:700px;'>" +
  32. "<tr><td style='min-width:30%; border-top:1px solid #dddddd;'><b>Email:</b></td><td style='border-top:1px solid #dddddd;' bgcolor='#f8f8f8'>" + CurrentRow[1] + "</td></tr>" +
  33. "<tr><td style='min-width:30%; border-top:1px solid #dddddd;'><b>Timestamp:</b></td><td style='border-top:1px solid #dddddd;' bgcolor='#f8f8f8'>" + CurrentRow[0] + "</td></tr>" +
  34.  
  35. "<tr><td style='min-width:30%; border-top:1px solid #dddddd;'><b><font color='#0000ff'>Extraversion:</font></b></td><td style='border-top:1px solid #dddddd;' bgcolor='#f8f8f8'><B>" + CurrentRow[106] + "</B> out of 80<br><B><font color='#0000ff'>" + CurrentRow[112] + "</font></B>%<br><br>" +
  36. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='" + CurrentRow[112] + "%' height='6' style=''>" +
  37. "<tr><td width='100%' align='right'><B><font color='#0000ff'>&nabla;</font></B></td></tr>" +
  38. "</table>" +
  39. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='6' style='border:1px solid #222222; border-top:0px solid #222222;'>" +
  40. "<tr><td width='10%' style='border-left:0px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td></tr>" +
  41. "</table>" +
  42. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='16' style=''>" +
  43. "<tr><td width='50%' align='left'><font size='1' color='#999999'>Introverted</td><td width='50%' align='right'><font size='1' color='#999999'>Extroverted</td></tr>" +
  44. "</table>" +
  45. "</td></tr>" +
  46.  
  47. "<tr><td style='min-width:30%; border-top:1px solid #dddddd;'><b><font color='#0000ff'>Agreeableness:</font></b></td><td style='border-top:1px solid #dddddd;' bgcolor='#f8f8f8'><B>" + CurrentRow[107] + "</B> out of 80<br><B><font color='#0000ff'>" + CurrentRow[113] + "</font></B>%<br><br>" +
  48. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='" + CurrentRow[113] + "%' height='6' style=''>" +
  49. "<tr><td width='100%' align='right'><B><font color='#0000ff'>&nabla;</font></B></td></tr>" +
  50. "</table>" +
  51. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='6' style='border:1px solid #222222; border-top:0px solid #222222;'>" +
  52. "<tr><td width='10%' style='border-left:0px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td></tr>" +
  53. "</table>" +
  54. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='16' style=''>" +
  55. "<tr><td width='50%' align='left'><font size='1' color='#999999'>Not agreeable</td><td width='50%' align='right'><font size='1' color='#999999'>Agreeable</td></tr>" +
  56. "</table>" +
  57. "</td></tr>" +
  58.  
  59.  
  60. "<tr><td style='min-width:30%; border-top:1px solid #dddddd;'><b><font color='#0000ff'>Conscientiousness:</font></b></td><td style='border-top:1px solid #dddddd;' bgcolor='#f8f8f8'><B>" + CurrentRow[108] + "</B> out of 80<br><B><font color='#0000ff'>" + CurrentRow[114] + "</font></B>%<br><br>" +
  61. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='" + CurrentRow[114] + "%' height='6' style=''>" +
  62. "<tr><td width='100%' align='right'><B><font color='#0000ff'>&nabla;</font></B></td></tr>" +
  63. "</table>" +
  64. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='6' style='border:1px solid #222222; border-top:0px solid #222222;'>" +
  65. "<tr><td width='10%' style='border-left:0px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td></tr>" +
  66. "</table>" +
  67. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='16' style=''>" +
  68. "<tr><td width='50%' align='left'><font size='1' color='#999999'>Not conscientious</td><td width='50%' align='right'><font size='1' color='#999999'>Conscientious</td></tr>" +
  69. "</table>" +
  70. "</td></tr>" +
  71.  
  72.  
  73. "<tr><td style='min-width:30%; border-top:1px solid #dddddd;'><b><font color='#0000ff'>Neuroticism:</font></b></td><td style='border-top:1px solid #dddddd;' bgcolor='#f8f8f8'><B>" + CurrentRow[109] + "</B> out of 80<br><B><font color='#0000ff'>" + CurrentRow[115] + "</font></B>%<br><br>" +
  74. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='" + CurrentRow[115] + "%' height='6' style=''>" +
  75. "<tr><td width='100%' align='right'><B><font color='#0000ff'>&nabla;</font></B></td></tr>" +
  76. "</table>" +
  77. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='6' style='border:1px solid #222222; border-top:0px solid #222222;'>" +
  78. "<tr><td width='10%' style='border-left:0px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td></tr>" +
  79. "</table>" +
  80. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='16' style=''>" +
  81. "<tr><td width='50%' align='left'><font size='1' color='#999999'>Relaxed</td><td width='50%' align='right'><font size='1' color='#999999'>Neurotic</td></tr>" +
  82. "</table>" +
  83. "</td></tr>" +
  84.  
  85.  
  86. "<tr><td style='min-width:30%; border-top:1px solid #dddddd;'><b><font color='#0000ff'>Openness to experience:</font></b></td><td style='border-top:1px solid #dddddd;' bgcolor='#f8f8f8'><B>" + CurrentRow[110] + "</B> out of 80<br><B><font color='#0000ff'>" + CurrentRow[116] + "</font></B>%<br><br>" +
  87. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='" + CurrentRow[116] + "%' height='6' style=''>" +
  88. "<tr><td width='100%' align='right'><B><font color='#0000ff'>&nabla;</font></B></td></tr>" +
  89. "</table>" +
  90. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='6' style='border:1px solid #222222; border-top:0px solid #222222;'>" +
  91. "<tr><td width='10%' style='border-left:0px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td><td width='10%' style='border-left:1px solid #222222;'></td></tr>" +
  92. "</table>" +
  93. "<table cellpadding='0' cellspacing='0' border='0' valign='top' width='100%' height='16' style=''>" +
  94. "<tr><td width='50%' align='left'><font size='1' color='#999999'>Closed to experiences</td><td width='50%' align='right'><font size='1' color='#999999'>Open to experiences</td></tr>" +
  95. "</table>" +
  96. "</td></tr>" +
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. "</table>" +
  104. "<br><br>" +
  105. "<p><b>Title: </b>" + CurrentRow[2] + "</p>" +
  106. "<p><b>Agency: </b>" + CurrentRow[3] + "</p>" +
  107. "<p><b>Summary: </b>" + CurrentRow[4] + "</p>" +
  108. "<p><b>Due: </b>" + CurrentRow[5] + "</p>" +
  109. "<p><b>Posted: </b>" + CurrentRow[6] + "</p>" +
  110. "<p><b>Total Funding: </b>" + CurrentRow[7] + "</p>" +
  111. "<p><b>Announcement Number: </b>" + CurrentRow[8] + "</p>" +
  112. "<p><b>Useful Links: </b>" + CurrentRow[9] + "</p><br><br>"
  113. ;
  114.  
  115. //set the row to look at
  116. var setRow = parseInt(i) + StartRow;
  117.  
  118. //mark row as "sent"
  119. ActiveSheet.getRange(setRow, 105).setValue("sent");
  120. }
  121.  
  122. //define who to send grants to
  123. var SendTo = "steven@nuttersons.co.uk";
  124.  
  125. //set subject line
  126. var Subject = "Pre-employment test email";
  127.  
  128.  
  129. //send the actual email
  130. MailApp.sendEmail({
  131. to: SendTo,
  132. cc: "",
  133. subject: Subject,
  134. htmlBody: message,
  135. });
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement