我有 2 个 google.script.run.withSuccessHandler 调用一个接一个发生,当我尝试将两者结合时,它不起作用。这是有效的代码,所有主要内容都受到影响。
//These are in a javascript function which executes when a submit button is clicked.
google.script.run.withSuccessHandler(updateOutput).processForm(frmData);
google.script.run.withSuccessHandler(returnMessage).sendEmail(theData, titles);
//server functions
function processForm(theForm) {
try{
var fileBlob1 = theForm.resumeFile;
var fldrSssn = DriveApp.getFolderById('My Folder ID');
fldrSssn.createFile(fileBlob1);
return 'good';
}catch(e) {
}//End catch
}
function sendEmail(arr, titles) {
try {
//This function sends an email and edits a spreadsheet. Nothing is affected
return 'Request Submitted';
}
}
但是当我尝试将两者结合起来时,程序会识别出提交按钮已被单击,但它不会越过 google.script.run.withSuccessHandler 命令。
//google.script.run.withSuccessHandler(updateOutput).processForm(frmData);
google.script.run.withSuccessHandler(returnMessage).sendEmail(theData, titles, frmData);
function sendEmail(arr, titles, theForm) {
try {
//Uploads the files
var fileBlob1 = theForm.resumeFile;
var fldrSssn = DriveApp.getFolderById('My Folder ID');
fldrSssn.createFile(fileBlob1);
var url1;
//Contains the rest of the code for sending an email and editing a spreadsheet.
return 'Request Submitted';
}
}
这是行不通的。有谁知道为什么会失败?当第一个函数成功时调用的函数都只显示一个弹出窗口,告诉用户他们的响应已提交。
最佳答案
来自谷歌文档:
A form element within the page is also legal as a parameter, but it must be the function’s only parameter.
您不能通过表单元素传递任何其他内容,它必须是唯一的参数。
Google Documentation - google.script.run.function(parameter)
关于javascript - Google Apps 脚本 google.script.run.withSuccessHandler 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31192244/