[英]UI Error while calling app script functions through app script API
I have written functions in the app script bound to a google sheet that validates sheet data and shows a pop up in the sheet when there is an error.我在绑定到谷歌工作表的应用程序脚本中编写了函数,该工作表验证工作表数据并在出现错误时在工作表中显示一个弹出窗口。
Now, I am calling same functions form API calls in a Node js application to return a validation response without interacting google sheet.现在,我在 Node js 应用程序中调用 API 调用相同的函数来返回验证响应,而无需交互谷歌表。
API calls are successful, function gets called but unable to initialize UI. API 调用成功,function 被调用但无法初始化 UI。 I just don't want to write duplicate functions for same purpose but without accessing UI.我只是不想为相同的目的编写重复的函数,但又不想访问 UI。
I get an error that says Script error message: Exception: Cannot call SpreadsheetApp.getUi() from this context.我收到一条错误消息,显示脚本错误消息:异常:无法从此上下文中调用 SpreadsheetApp.getUi()。
How do I solve this issue by retaining the UI calling functionality of the app script functions and also getting work done through API?如何通过保留应用脚本函数的 UI 调用功能并通过 API 完成工作来解决此问题?
You can put the call in a try catch block.您可以将调用放在 try catch 块中。
try {
SpreadsheetApp.getUi();
} catch (f) {
// do nothing here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.