-2

I'm trying to make a Google Sheets script in Google App Script to respond to changes to a spreadsheet from a form. it will eventually be used to send an email to the user with a list of URLs to access cloud documents based off their subject choices. My code doesn't seem to be doing anything. Any ideas?

The list of subjects is "Maths - Methods, Maths - Applications, Maths Essentials, English - 1, English - 2, English - 3, Science - 3, Science - 2, Science - 1, HASS Extension, HASS, PHYS ED, Drama, Music, Imaging and Animation, Engineering, Wood, Metal, World of Money, Databases and Programming, Chinese, French, Japanese, Auslan, Ancient History, Cooking, Photography, Art, Media"

See below:

function myFunction(e){
var userName = e.values[2];
var userEmail = e.values[1];
var discord = e.values[7];
var subj = e.values[3]; // gets a list of subjects - like " Maths - Methods, English - 3"
var subj = subj.split(', '); // splits the list into an array

  //checking if contains Maths methods
var n = subj.includes("Maths - Methods");
if (n == true);
  var index = items.indexOf("Maths - Methods");
  subj[index] = "URL"; //replaces Maths - Methods in the array with URL
  var n = false
  var index = 0

var subject = "Notinizer Application";
var message = "Hi there, " + userName + " for choosing " +subj;

MailApp.sendEmail (userEmail, subject, message);}
  • _My code doesn't seem to be doing anything. _ What precisely do you mean by this statement? – Tedinoz Mar 27 at 5:39
  • It won’t run at all. It errors at line 2. – James Scoobie Mar 28 at 6:02
  • If it is failing at line2, then it is a fair bet that the Event Objects are undefined - which makes it a fair bet that the trigger isn't installed. So... have you installed an onFormSubmit trigger? – Tedinoz Mar 28 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.