【问题标题】:How to get Google sheet Apps Script to run onOpen function for all users with edit permissions如何让 Google sheet Apps Script 为所有具有编辑权限的用户运行 onOpen 函数
【发布时间】:2018-06-14 23:57:41
【问题描述】:

我有一个显示方向的弹出框,但它仅在我打开工作表时显示。我希望它在任何有权访问它的用户打开它时运行。澄清一下,其他用户都是编辑。

我的 toast box 确实会显示给其他用户,但 html 应用程序没有

这是我的脚本:

    function onOpen() {
      var message = "Let's have a productive day!";
      var title = 'Welcome Back Greeter';+
      SpreadsheetApp.getActiveSpreadsheet().toast(message, title, 10);


      var htmlApp = HtmlService
         .createHtmlOutput('<p>Make sure you mark the following each time a plate is taken or returned: </p>----Salesperson Name </p>----Time Out </p>----Time In </p>----and if it is Pupped! </p>Do not let Salespeople take plates themselves! </p>As Greeters we are responsible for tracking these plates. This sheet is going to be reviewed with Bob each night with a list of which plates are out for the night as well as a list of the plates that are currently in their folders for the next day. </p> Sincerely, The Plate Fairy</p>')
         .setTitle('!!!!!  ATTENTION GREETER  !!!!!')
         .setWidth(350)
         .setHeight(400);

      SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
    }

【问题讨论】:

  • 添加执行脚本。
  • 第三行 (var title = 'Welcome Back Greeter';+) 的 ; 后面有一个 +。也许这就是问题所在。
  • 我会选择从图像点击运行代码创建菜单选项。两者都可以正常工作,并且不需要人们在脚本运行之前对其进行授权。如果他们不授权,它将不会为他们运行。在他们查看工作表后检查 Stackdriver 上的控制台日志以自行验证。

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


【解决方案1】:

用户必须授予您的脚本权限才能打开对话框。因此,您需要让他们创建一个installable onOpen trigger,他们将授权并在随后的打开时显示您的对话框。

您无法强迫他们这样做,您只能为他们提供类似于自定义菜单选项的选项。

【讨论】:

    【解决方案2】:

    仅当文档(在本例中为电子表格)由所有者或编辑者打开时才会触发简单触发器。另一方面,简单的触发器有几个限制,比如它们不能打开对话框、侧边栏等等。

    详情见Simple Triggers

    值得注意的是,目前有一些未解决的问题可能与此线程相关。我已经在回复"You do not have permission to call showModalDialog"时提到了他们

    【讨论】:

    • 其他用户是编辑
    • @JonathanRupell 请编辑您的问题以明确说明。
    • 我怀疑简单的触发器是否有权在没有用户交互的情况下显示侧边栏或模式对话框
    猜你喜欢
    • 2018-10-20
    • 2020-11-25
    • 2015-10-09
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多