Google Apps Script for Form, Generate Unique ID Number

白昼怎懂夜的黑 提交于 2019-12-05 21:30:18

try it like this :

(added comment in code and deleted repetitions)

function sendFormByEmail(e)   
{      
var capsht = SpreadsheetApp.getActiveSheet();  
var caprow = capsht.getLastRow();  
var codenumber = "Cap-"+caprow
capsht.getRange(caprow,5).setValue(codenumber);  

var admin = "admin@xxx.com";  

try {  

var recipient = e.namedValues["Email"];  
var subject = "Capacity Request Form Received";    

var headers = capsht.getRange(1,1,1,capsht.getLastColumn()).getValues()[0];      
var message = "";      

for(var i in headers)  
if(i!=4){ 
message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n";   
}else{  // if i==4 (column nr5)then use your code number
message += headers[i] + ' = '+ codenumber + "\n\n"; 
}
MailApp.sendEmail(recipient, subject, message);   

}   

catch (error)  
{  
MailApp.sendEmail(admin, "Error with form submission response email", error.message);  
}  

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!