Update Google Forms field based on dynamic data from a Google Sheets spreadsheet

无人久伴 提交于 2020-01-05 03:08:05

问题


In a Google Form we have a pull down selection list.

The list of items may change from minute to minute. The master copy of the data is in a column in a google docs spreadsheet.

When a user accesses the form, we want them to see the latest copy of the pull down list as is current in the spreadsheet.

I don't see an obvious way to do this with triggers. onOpen, for example, only triggers for administrators of the form, not users. Is there a way I can keep this form up-to-date automatically?

This is my first time in google docs, but I'm very experienced in excel scripting.


回答1:


The work flow needs to be a bit different than what you've described. Since there is no ability for Google Apps Script to interact with an end user accessing a Form, there's no way to react to that. However, you can react to changes in the spreadsheet, and update the form options in preparation for the next end user.

  • Depending on how the options get updated in the spreadsheet, you can use an installable trigger there, to react to an edit or a change.

  • If the form is associated with the spreadsheet containing the choices, you can get a handle on the form using Spreadsheet.getFormUrl(), then pass the URL to FormApp.openByUrl(). Otherwise you will need to provide the ID or URL explicitly to FormApp.openById() or .openByUrl(), respectively.

  • That spreadsheet trigger function can modify the available selections for the relevant question by using ListItem.setChoices() or ListItem.setChoiceValues().



来源:https://stackoverflow.com/questions/28894664/update-google-forms-field-based-on-dynamic-data-from-a-google-sheets-spreadsheet

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