对于 Google Apps 脚本端的
从:
我在Google表格上链接了一个按钮,当用户点击时,它会运行此功能:
function ModalSelection(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('main_gen');
var cell = ss.getRange(1,1).getValue();
if(cell == ''){
checkWindow(); //It runs this function if `cell` is empty.
//I would like to run another function here...anotherFunction()...but not until
//the user has made their selections from the Modal Dialog box.
}
else {send();} //send is not relevant to this question.
}
这是checkWindow()
函数:
function checkWindow(){
var ui = SpreadsheetApp.getUi();
var result = emailList(); //This is a string grabbed from another function.
//Call the HTML file and set the width and height
var html = HtmlService.createHtmlOutput(result)
.setWidth(400)
.setHeight(450);
//Display the dialog
var dialog = ui.showModalDialog(html, "Select your choices here.");
}
当运行checkWindow()
函数并且用户选择"提交"时,它会运行另一段简短的代码(见下文(,将用户选择插入到单元格中。我需要等到这个单元格不再为空,然后再继续下一个函数。
function form_data(e){
SpreadsheetApp.flush();
var value = [e.email];
var val = value[0].toString();
for(var i = 1; i<value.length; i++){val += ', ' + value[i];}
SpreadsheetApp.getActiveSheet().getRange(2, 2).setValue(val);
//I have tried adding the anotherFunction(); function right here, but the code breaks and the only error I see
//in the console error log is "Uncaught". It gives me no additional details.
}
编辑以包含所有 HTML。
HTML 代码如下(电子邮件复选框.html(:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body>
<form id='myform'>
<table border=0>
%email
</table>
</form><br>
<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.host.close).form_data(document.getElementById('myform'))"/>
<input type="button" value="Close" onclick="google.script.host.close()"/>
</body>
它所指的%email是这个JS代码:
function checkEmail(List){
var output = '';
for(var i=0; i<List.length; i++)
{
output += '<tr><td><input type="checkbox" name="email" id="' + List[i] + '" value="' + List[i] + '"/>'+ List[i] + '</td></tr>';
}
var result = HtmlService.createHtmlOutputFromFile('EmailCheckBox').getContent();
result = result.replace('%email', output);
Logger.log(result);
return result;
}
</html>
结束编辑
有什么想法吗?谢谢!
我相信你的目标如下。
- 您想在
checkEmailWindow
对话框中打开该过程完成后sendCheck
对话框。
为此,进行此修改怎么样?
修改点:
- 在脚本中,
checkEmailWindow()
和sendCheck()
是连续运行的。这样,checkEmailWindow()
打开的对话框将被sendCheck()
打开的对话框覆盖。我认为这就是您问题的原因。 - 为了在
checkEmailWindow
对话框中完成该过程后打开sendCheck()
对话框,我修改了google.script.run.withSuccessHandler(google.script.host.close).form_data(document.getElementById('myform'))
如下。google.script.run.withSuccessHandler(google.script.run.sendCheck).form_data(document.getElementById('myform'))
- 这样,在
checkEmailWindow
对话框中完成该过程后,将打开sendCheck
对话框。
对于 Google Apps 脚本端的send()
:
从:if(bccSend == ''){
checkEmailWindow();
sendCheck();
}
自:if(bccSend == ''){
checkEmailWindow();
// sendCheck(); // Removed
}
HTML 和 Javascript 方面:
从:<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.host.close).form_data(document.getElementById('myform'))"/>
自:<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(google.script.run.sendCheck).form_data(document.getElementById('myform'))"/>
sendCheck
运行withSuccessHandler
.