Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Apps脚本调用函数,该函数执行一个模式对话框,然后在用户做出选择后执行另一个函数_Javascript_Google Apps Script - Fatal编程技术网

Javascript Google Apps脚本调用函数,该函数执行一个模式对话框,然后在用户做出选择后执行另一个函数

Javascript Google Apps脚本调用函数,该函数执行一个模式对话框,然后在用户做出选择后执行另一个函数,javascript,google-apps-script,Javascript,Google Apps Script,我在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 `ce

我在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.
}
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 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.
}
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. 
}
函数形式_数据(e){
SpreadsheetApp.flush();
var值=[e.email];
var val=值[0]。toString();

对于(var i=1;i我相信您的目标如下

  • 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)。表单数据(document.getElementById('myform'))
    • 这样,在
      checkEmailWindow
      对话框中完成该过程后,将打开
      sendCheck
      对话框
对于Google应用程序脚本端的
send()
: 发件人: 致: HTML和Javascript端: 发件人:

致:

  • sendCheck
    使用
    withSuccessHandler
    运行

为了正确理解
的内容,我需要等待此单元格不再为空,然后才能继续下一个函数。
,您能否向我们展示
html
?@Tanaike我已编辑了原始问题以添加html部分。感谢您的回复和添加更多信息。在您的脚本中,if
document.getElementById('myform')
可以为
表单数据(e)
发送正确的值,在
表单数据的脚本完成后,
google.script.host.close
正在运行。如何?如果您想在
SpreadsheetApp.getActiveSheet().getRange(2,2)之后使用put值(e)
,如何放置
SpreadsheetApp.flush()
在那一行之后?但我不确定这是否是你期望的方向。因此,如果这不是你期望的方向,我很抱歉。@Tanaike…我尝试了但没有用。我会给你发送一个示例电子表格。给我几分钟。谢谢!@Tanaike这是电子表格:只要运行
send()
Send.gs文件中的函数。在立即转到下一个函数之前,您会看到它会在弹出窗口中短暂闪烁。非常好。谢谢!@hunter21188感谢您的回复和测试。我很高兴您的问题得到解决。也谢谢您。
if(bccSend == ''){
  checkEmailWindow();
  sendCheck();
}
if(bccSend == ''){
  checkEmailWindow();
  // sendCheck();  // Removed
}
<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'))"/>