Reputation: 11
We have a lot of google Form with related answers files. All spreadsheet files with answers contain a GScript which run by trigger "On send form"
But only one form stopped run this script. Answer write into spreadsheet correct, but related script seems doesn't execute.
This script receive object trigger event and send email with last row from spreadsheet
function sendFormByEmail(e) {
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
....
....
GmailApp.sendEmail(email, subject,messageTxt,{'htmlBody':messageHTML,'name': 'HR-bot'});
}
So strange that we have exactly the same script in other spreadsheet and it works perfect!
Moreover if comment all this script and leave only row with GmailApp.sendEmail and send GoogleForm , answers write into spreadsheet correct but trigger "On send form" may not occurs and even that one row not execute
Thanks for help
P.S. How to debug this type of script that takes Event Object Argument ?
Upvotes: 0
Views: 279
Reputation: 11
Thanks to Rubén , i have use this approach How can I test a trigger function in GAS?
And that's my result:
var dataRange = SpreadsheetApp.getActiveSheet().getDataRange();
var data = dataRange.getValues();
var lastRow = data[data.length-1];
var headers = data[0];
for (var row=1; row < data.length; row++) {
var e = {};
e.values = data[row].filter(Boolean);
e.range = dataRange.offset(row,0,1,data[0].length);
e.namedValues = {};
// Loop through headers to create namedValues object
// NOTE: all namedValues are arrays.
for (var col=0; col<headers.length; col++) {
e.namedValues[headers[col]] = [data[row][col]];
}
}
lastRow variable contain value of lastRow and with Debug i found that all my code works perfect And accidentally i have recreated Answer file and deleted connection between form and answer file Create new answer file and place into my code. And it works!
Summary: if you think that your answer file doesn't pass trigger event object or even doesn't run a .gs "On send form" - just clear answers from form and attach it to absolutely new answer file
Upvotes: 1