简体   繁体   中英

Filling cells in range if empty in google spreadsheet form submission

I'm trying to make a script that sends out a custom email confirmation to the user. However, I noticed that if any of the cells are blank the script will not work. I was wondering how to I like highlight the last entry of the table and check the cells, that if the cell is empty then change it's value to 0 or a dash. Here's what I got going:

function Confirmation(e) {
 var sheet = SpreadsheetApp.getActiveSheet();
 var lastRow = sheet.getLastRow();
 var lastRange = sheet.setActiveRange(sheet.getRange(lastRow,5,1,2));
 //lastRange.setValues(1111);

 var EmailAdd = e.values[1];
 var Name = e.values[2];
 var Type = e.values[3];
 var Criteria1 = e.values[4];
 var Criteria2 = e.values[5];
 var Criteria3 = e.values[5];

 MailApp.sendEmail(EmailAdd, "Your request has been received" , 
                  "Thank you, " + Name + " for submitting your request.
                )

}

the lastRange line already highlights the last entry. How can I evaluate each cell and check if it's empty change it's value and if not move to the next cell.

*I always get an "cannot read property "values" from undefined" is this because it's empty or because I set it as an event triggered function. Sorry I'm new to javascript & google apps script

As indicated in the comment above, Mogsdad's link provides a good work around for this problem. See link: e.values in google forms skips empty answers, is there a workaround?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM