Conditional Script to send email from Form

67 views
Skip to first unread message

Wayne Mak

unread,
Oct 16, 2022, 7:47:52 PM10/16/22
to Google Apps Script Community
Hi,  I am trying to get a conditional script to email me if a YES/NO question in a form is has YES selected.  The email message needs to include text from a couple of previous questions in the form.  How do I;

a) get the trigger to be based on the YES/NO question
b) how do I get the values from a couple of other questions in the form to be included in the email.

Cheers 
Mak

Wayne Mak

unread,
Oct 17, 2022, 1:25:20 AM10/17/22
to Google Apps Script Community
Got all but one part working which is to evaluate whether a question is answered yes or no with the yes triggering the email being sent.  At the moment the emails are being sent of every new response.  This is triggered by a form submission to the spreadsheet that holds the values.


function ChkContactReq() {
  
  // Set intial variable state
  var supportVal = "No"

  // Find the last row number and set the variable
  var lastRow = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form responses 1").getLastRow()
  var lastRowID = lastRow  

   // Get Interviewer Name Value
  var pInterviewerQ = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form responses 1").getRange("C"+ lastRow)
  var pInterviewer = pInterviewerQ.getValue()

  // Get ID Value
  var pIDQ = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form responses 1").getRange("I"+ lastRow)
  var pID = pIDQ.getValue()

  //Get Support Contact Value YES/NO
  var supportReq = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form responses 1").getRange("H"+ lastRow)
  var supportVal = supportReq.getValue()

   // If anwser is YES send email
  if (supportVal = "Yes"){
var emailAddress = 'MY_EMAIL_ADDRESS';
var message = 'Interviewer '+ pInterviewer +' needs assistance for interviewee ID ' + pID;
var subject = supportVal + ' Supervisor Contact Requested';
MailApp.sendEmail(emailAddress, subject, message);

  } else {
 }
 }

Andrew Roberts

unread,
Oct 17, 2022, 1:31:36 AM10/17/22
to google-apps-sc...@googlegroups.com
Note the triple equals.

 if (supportVal === "Yes"){

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/94cb27bf-de39-4412-a86d-92d31ec0e062n%40googlegroups.com.

Wayne Mak

unread,
Oct 17, 2022, 1:36:22 AM10/17/22
to Google Apps Script Community
Top man.  Much appreciated.

Cheers Andrew

Reply all
Reply to author
Forward
0 new messages