【问题标题】:Google Apps Script: Alerts display for spreadsheet owner but not for editorsGoogle Apps 脚本:向电子表格所有者显示警报,但不向编辑者显示
【发布时间】:2020-01-27 19:00:18
【问题描述】:

以下脚本通过容器绑定到 Google 表格电子表格。当用户单击工作表上的按钮时,会启动一个模式对话框来收集输入。此输入用于制作另一个电子表格的副本。在脚本结束时会出现一个警告,告诉用户在哪里可以找到已创建的新电子表格。目前,所有这些电子表格都驻留在 Google 共享驱动器中。最终,他们需要驻留在可以共享的常规 Google 云端硬盘中,但我试图先解决此问题,然后再在该设置中进行调试。

function scheduleAccount() {
  // Request user input to generate name of new spreadsheet
  var htmlOutput = HtmlService.createHtmlOutputFromFile('scheduleAccountUI')
    .setWidth(300)
    .setHeight(300);
  SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Account Information');

}

function checkIfAccountScheduleExists(values) { //values is an object containing name-value pairs returned by the form in scheduleAccountUI.html
  console.log(values);

  var current_file = DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId());
  var current_folder = current_file.getParents().next();
  console.log('Current folder: ' + current_folder);

  // Check whether a file already exists with the same name
  var filename = values["acctref"] + ' Schedule';
  var schedule_exists = current_folder.getFilesByName(filename).hasNext();
  console.log('Schedule exists?: ' + schedule_exists);
  if (schedule_exists) {
      SpreadsheetApp.getUi().alert("Oops - it looks like you've already created a schedule for that account.");
  } else {
   createNewAccountSchedule(values, filename, current_folder);
  }

}

function createNewAccountSchedule(values, filename, current_folder) { //values is an object containing name-value pairs returned by the form in scheduleAccountUI.html

  // Make a copy of the Account Schedule template
  var template = DriveApp.getFilesByName('Template - Account Schedule').next();
  var new_schedule_ID = template.makeCopy(filename, current_folder).getId();
  console.log('New schedule ID: ' + new_schedule_ID);

  // Tell user where to find the new spreadsheet  
  SpreadsheetApp.getUi().alert("Template created! You'll find it in the same folder as this dashboard, with the filename " + values["acctref"] + " Schedule.");
  console.log('Alert displayed');

}

当我自己运行脚本时一切正常。但是,当另一个编辑但不是电子表格所有者的用户运行它时,会出现模式对话框,并且脚本中的所有其他内容都按预期运行,但最终警报永远不会出现。根据 Stackdriver 日志,脚本在等待用户响应时超时。

如果我在应该触发“糟糕,该计划已存在”警报的上下文中运行脚本,则该警报也不会出现。

我在文档中找不到任何关于警报需要特殊权限的信息。有谁知道可能导致这种行为的原因是什么?如何让警报显示给所有用户?

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    this question 的答案原来也是我的答案,尽管我的脚本没有抛出错误。我注销了所有 Google 帐户并仅重新登录到编辑/非所有者帐户,并且警报按预期显示。我把这个问题和答案留在这里,以防它帮助别人。

    【讨论】:

      猜你喜欢
      • 2019-12-20
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 2021-11-02
      • 2021-06-26
      相关资源
      最近更新 更多