Joseph Sanders
Joseph Sanders

Reputation: 143

Google Apps Script trigger on form submit

I have a simple script that seems to work only if I edit the Specific field where I am looking for "On Campus". Currently, i have to edit the field to something different, then change it back to "On Campus" before the script will fire off.

What I want, is when the form is submitted, if the specified field says "On Campus" I want this script to fire off.

Any ideas why its only working if I manually edit the field? I have set the trigger to be on Form Submit.

function sendEmailSupervisor(e) {
  if (e.range.columnStart != 11 || e.value != "On Campus") return;
  const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,21).getValues();
  let a = rData[0][0];
  let b = rData[0][1];
  let c = rData[0][4];
  let d = rData[0][5];
  let f = rData[0][6];
  let now = new Date().toLocaleString("en-US");
  
  let msg = "Date/Time Submitted: "+ a + "\n \n" + "Email Address:  " + b +  "\n \n" + "Person Requesting? " + c +  "\n \n" + "Name of the event? " + d +  "\n \n" + "Description of the event? " + f +  "\n \n" + " Form Submitted:  " + now;
  Logger.log(msg);
  GmailApp.sendEmail("[email protected]", "On Campus Event Submitted", msg)
}

enter image description here

Upvotes: 0

Views: 3096

Answers (1)

TheWizEd
TheWizEd

Reputation: 8598

I'm not able to test this but it should work.

function sendEmailSupervisor(e) {
  Logger.log(e.values); // just so you can see what values are
  if( e.values[10] !== "On Campus" ) return;  // column K
  let a = e.values[0];
  let b = e.values[1];
  let c = e.values[4];
  let d = e.values[5];
  let f = e.values[6];
  let now = new Date().toLocaleString("en-US");
  
  let msg = "Date/Time Submitted: "+ a + "\n \n" + "Email Address:  " + b +  "\n \n" + "Person Requesting? " + c +  "\n \n" + "Name of the event? " + d +  "\n \n" + "Description of the event? " + f +  "\n \n" + " Form Submitted:  " + now;
  Logger.log(msg);
  GmailApp.sendEmail("[email protected]", "On Campus Event Submitted", msg)
}

Upvotes: 2

Related Questions