javascript - 如何根据表单输入值从谷歌表单获取新的响应到不同的文件夹
问题描述
我有一个包含问题的表格
- 提单号
- 进口商代码
- 每个用户提交响应时上传文件,文件应保存在不同的文件夹中,文件夹名称应为问题“BL编号”的输入值。我们怎样才能使它成为可能?
解决方案
这在很大程度上取决于您的表单的外观。
这是一个如何完成的示例。
假设您有一个非常简单的表格,如下所示:
它有两个 'namedValues':Folder
和File
,它们将在下面的脚本中使用。
下一步:您必须在表单中添加一个“链接”电子表格。
在此电子表格中,您必须添加此脚本:
// names and IDs of your destination folders
var folders = {
'aaa' : '###', // <-- you have to change ### with a real ID
'bbb' : '###',
'ccc' : '###'
}
function move_file_to_folder(e) {
// get folder ID from folders object
var folder_id = folders[e.namedValues['Folder'][0]]; // <-- the name from the named value 'Folder'
// get file ID from the form
var file_id = e.namedValues['File'][0].split('id=')[1]; // <-- the url from the named value 'File'
// move the file into the folder
DriveApp.getFileById(file_id).moveTo(DriveApp.getFolderById(folder_id));
}
// this function should be run just once to install the trigger
function install_OnFormSubmitTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger('move_file_to_folder')
.forSpreadsheet(ss)
.onFormSubmit()
.create();
}
之后,您必须运行该功能install_OnFormSubmitTrigger()
来安装触发器。
move_file_to_folder()
为了获得适当的访问权限,运行该函数可能也很有意义。它会给你一个错误。别介意。保持冷静并进行。
现在,每次您提交表单时,上传的文件都会进入具有相应名称的文件夹(在我的示例中为“aaa”、“bbb”、“ccc”)。
推荐阅读
- node.js - 将无效 id 传递给 findByIdAndUpdate 时出现 UnhandledPromiseRejectionWarning
- selenium - 如何在 Blazor 应用程序的 Selenium / Puppeteer 测试中等待导航完成
- wordpress - 如何在 Elementor 中使用 Buddypress 个人资料字段?
- javascript - 无法读取未定义 [React.js] 的属性“地图”
- java - 如何删除小数点后的空格而不删除其他空格?
- visual-studio - 转到定义不起作用 Visual Studio 2019 尝试了一切都没有运气
- node.js - npm 错误!安装 ReactJS 时代码 ERR_OSSL_PEM_NO_START_LINE 和例程:get_name:no start line
- javascript - 修改 Joi 模式以使用不同的值
- android - 启动应用程序时 Xamarin Android 崩溃
- python - 字符串索引。如何检索字符串的最后三个字母