我有一个Google表单,用户输入他们正在注册的运动。他们输入了他们的电子邮件,地址,姓名等。然后,我在电子表格中添加了一个总计列,这是 arrayformula ,根据他们的答案计算他们的总数欠。带有用户提交表单的电子表格效果很好。
但是在Script Manager中我有一个在onFormSubmit上触发的函数(见下文)。当用户填写并提交表单时,会发送“确认”电子邮件,并且所有字段都应该是它们应该是除了总计出现未定义 - 这是arrayformula列。为什么?我们无法发送这些字段吗?我真的需要电子邮件告诉用户他们欠多少钱。 如何引用用户刚提交的行的“总计”列?
function onFormSubmit(e) {
var timestamp = e.values[0];
var toAddress = e.values[1];
var LastName = e.values[2];
var Street = e.values[3];
var City = e.values[4];
var Zip = e.values[5];
var Phone = e.values[6];
var Student1 = e.values[7];
var GradeS1 = e.values[8];
var BdayS1 = e.values[9];
var GenderS1 = e.values[10];
var SportS1 = e.values[11];
var Student2 = e.values[12];
var GradeS2 = e.values[13];
var BdayS2 = e.values[14];
var GenderS2 = e.values[15];
var SportS2 = e.values[16];
var Student3 = e.values[17];
var GradeS3 = e.values[18];
var BdayS3 = e.values[19];
var GenderS3 = e.values[20];
var SportS3 = e.values[21];
var Student4 = e.values[22];
var GradeS4 = e.values[23];
var BdayS4 = e.values[24];
var GenderS4 = e.values[25];
var SportS4 = e.values[26];
var Total = e.values[30];
var subject = "Registration";
var htmlBody = "The Registration details you entered were as follows:" +
"<br/><br/> Date/Time Submitted: " + timestamp +
"<br/> Family: " + LastName +
"<br/> Address: " + Street + ", " + City + ", " + Zip +
"<br/> Phone: " + Phone +
"<br/> Student 1: " + Student1 + ", " + GradeS1 + ", " + BdayS1 + ", " + GenderS1 + ", " + SportS1 +
"<br/> Student 2: " + Student2 + ", " + GradeS2 + ", " + BdayS2 + ", " + GenderS2 + ", " + SportS2 +
"<br/> Student 3: " + Student3 + ", " + GradeS3 + ", " + BdayS3 + ", " + GenderS3 + ", " + SportS3 +
"<br/> Student 4: " + Student4 + ", " + GradeS4 + ", " + BdayS4 + ", " + GenderS4 + ", " + SportS4 +
"<br/><br/> TOTAL DUE: <b>$" + Total +
"</b><br/><br/>Please send your payment, <b>checks payable to Our Company </B> , to: <font color=\"red\"><b>Person Name</font></b>" +
"<br/><br/>Your registration will not be activated until payment is received. Thank you so much!" +
"<br/><br/>From Our Company";
var optAdvancedArgs = {name: "Our Company", htmlBody: htmlBody};
MailApp.sendEmail(toAddress, subject, "Message Body", optAdvancedArgs);
}
谢谢,如果你可以帮忙的话,拜托!
答案 0 :(得分:0)
你可以发布你的数组代码吗?我猜这个数组的长度可能小于30(29)。那个或数组以某种方式不能正确插入数据。我还想在声明一个值时抛出一个.toString();
答案 1 :(得分:0)
正如您在问题中提到的那样,TOTAL变量未在表单中定义,而是在电子表格中定义...因此,它与链接到/同时出现的任何e.parameter
不对应是正常的。表格。 (e.values [x]引用了表单问题索引,而不是电子表格列,即使在实践中它们是相同的参考数字)
你应该尝试将这个值放在原处,即在电子表格中!
由于我不知道您的电子表格布局,我无法告诉您它的位置,但您应该能够轻松完成。
另一种可能的选择是通过在脚本级别执行与电子表格单元格相同的操作来处理脚本本身中的数据...如果只是添加变量值,则实现起来应该不会太难。