Google Apps脚本:withSuccessHandler在不运行google.script.run.myFunction()的情况下运行

时间:2019-01-30 22:18:54

标签: html google-apps-script google-sheets

在Google表格中,我创建了一个Apps脚本以在对话框中打开html表单。除表单上的某些输入字段外,还有两个按钮-保存/退出和保存/下一步。

虽然按钮应运行不同的服务器端功能,但一旦服务器确认收到,两个按钮都应关闭对话框。但是我发现服务器功能根本没有运行,但是无论如何withSuccessHandler似乎都在触发!

缩写代码: Code.gs

function newProposal() {
  var html = HtmlService.createHtmlOutputFromFile('frmBackground').setHeight(500).setWidth(1000);
  SpreadsheetApp.getUi()
  .showModalDialog(html, 'New Proposal');
}
function saveBackground(e) {
  SpreadsheetApp.getActive().toast("hello");
  Logger.log(e);
  sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Project Data");
  var alast = sheet.getRange("A3:A").getValues().filter(String).length;
  var inpCell = sheet.getRange("A" + (3+alast))
  inpCell.setValue(sheet.getRange("A" + (2+alast)).getValue()+1);
  inpCell = sheet.getRange("B" + (3+alast));
  inpCell.setValue(e.Opportunity)  
}

frmBackground.html

<!DOCTYPE html>
<html>
  <body>
  <form>
    <h2 style="text-align: center;"><span style="color: #800080;">PROJECT BACKGROUND</span></h2>
<p>&nbsp;</p>
<table style="height: 172px;" width="778" cellpadding="10">
<tbody>
<tr>
<td style="width: 187px;">
<p style="text-align: right;"><strong><span style="color: #800080;">Project Start Date:</span></strong></p>
</td>
<td style="width: 187px;"><input name="inp_Start" type="date" /></td>
<td style="width: 188px;"><strong><span style="color: #800080;">Opportunity ID:</span></strong></td>
<td style="width: 188px;"><input name="inp_Opportunity" size="3/" type="text" /> <strong><span style="color: #800080;">&nbsp;&nbsp;months</span></strong></td>
</tr>
.
.
.
</tbody>
</table>
<p>&nbsp;</p>
<p style="text-align: center;">
<input type="button" value="Save and Return" onclick="google.script.run.withSuccessHandler(google.script.host.close).saveBackground()"/>
<input type="button" value="Save and Continue" onclick="google.script.run.withSuccessHandler(google.script.host.close()).saveBackgroundNext()"/></p>
</form>
  </body>

</html>

我希望发生的事情: saveBackground()和saveBackgroundNext()中的代码应运行。该对话框不应关闭,因为我尚未编写返回值。

我也尝试过的:

  • 消除.withSuccessHandler并要求按钮运行 google.script.run.saveBackground()本身。没有回应。
  • 在html中创建一个试图执行google.script.run的函数的部分。没有回应。
  • 更改.withSuccessHandler以在关闭后删除()。没有响应,但这是预期的,因为没有成功消息触发它。

0 个答案:

没有答案