Google脚本无法从此上下文调用FormApp.getUi() [英] Google Script Cannot call FormApp.getUi() from this context

查看:93
本文介绍了Google脚本无法从此上下文调用FormApp.getUi()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从Google开发人员站点复制简单的示例来工作.

I can't get the simple example copied from the google dev site to work.

错误是:无法从此上下文调用FormApp.getUi()

The error is: Cannot call FormApp.getUi() from this context

我不是试图将其部署为Web表单/应用程序,而是尝试通过编辑器来运行它!

I am NOT attempting to deploy this a web form/app but I am simple trying to run this via the editor!!!

不确定我在做什么错吗?!?!?!

Not sure what I'm doing wrong?!?!?!

以下内容已粘贴到index.html中:

The following has been pasted into index.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Hello, World!
  </body>
</html>

将以下内容粘贴到Code.gs中:

The following is pasted into Code.gs:

// Use this code for Google Docs, Forms, or new Sheets.
function onOpen() {
  FormApp.getUi() 
      .createMenu('Dialog')
      .addItem('Open', 'openDialog')
      .addToUi();
}

function openDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Index');
  FormApp.getUi() 
      .showModalDialog(html, 'Dialog title');
}

推荐答案

回答了我自己的问题.

脚本必须绑定到表单(不是我的!)

The script must be bound to a Form (which mine wasn't!)

所以现在我需要弄清楚如何为未绑定脚本创建对话框.

So now I need to figure out how to create a Dialog for an Unbound script.

我认为这是不可能的!

如果将其部署为Web应用程序,那么显然我无权访问用户界面.

If I deploy it as a Web App then obviously I have no access to the user UI.

那么我将如何从ContentService.createTextOutput()的输出中获取文件并进行下载?

So how would I take the output from ContentService.createTextOutput() and cause a download of a file to occur?

这篇关于Google脚本无法从此上下文调用FormApp.getUi()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆