How to ask for user input in “on edit” installable trigger in Google Spreadsheet?

这一生的挚爱 提交于 2019-11-27 08:04:40

问题


When a user edits a cell in particular column to a particular value, messages are sent to a Telegram bot, depending on a new value.

This is implemented by an "installable trigger" on edit event. It is installed by the document owner and always runs under that account. There are other users editing the doc and triggering the action. All works fine.

Now for some action we need to request a few words from the user who made the edit.

But since November 2017 (see issue 68846962) "for security reasons" Google restricted their Apps Script and now Ui methods prompt() and showSideBar() are only available to the user who created the trigger. For others it causes "You do not have permission to call showSidebar()" error.

What workaround could there be to request and receive user input on the cell edit event for all users? Considering that further actions require permissions to access external services (call Telegram API).


回答1:


As a possible workaround, you can create separate sheet that will be your "form" for user input:

"Submit" button should be an image, assign function to it by context menu - "Assign script" (enter your function name to process "form" data):

Then your onEdit trigger should just activate "form" sheet for the current user when edit happened. Sample code:

function onEdit() {
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form').activate();
}

After filling the form user clicks on "Submit" image, then you can send data to external service, sample code:

function submit() {
  var response = UrlFetchApp.fetch("http://www.google.com/");
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Results').appendRow([response.getResponseCode(), new Date()]);
}


来源:https://stackoverflow.com/questions/47479954/how-to-ask-for-user-input-in-on-edit-installable-trigger-in-google-spreadsheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!