简体   繁体   English

如何让多个函数连续运行 - 谷歌应用程序脚本

[英]How to get multiple functions to run in a row - google app script

Before anyone says go look at other threads, I already checked out the following: Running Multiple Functions in Google Apps Script and How to execute multiple functions in google apps script in order?在有人说去看看其他线程之前,我已经检查了以下内容: 在 Google Apps 脚本中运行多个函数如何在 google 应用程序脚本中按顺序执行多个函数? and am still stuck.我仍然卡住了。

For reference, I have limited coding experience and have been teaching myself to do this one specific task and a couple other document auto fill app scripts (which work fine but are individual) for my job.作为参考,我的编码经验有限,并且一直在自学为我的工作完成这项特定任务和其他几个文档自动填充应用程序脚本(它们工作正常,但都是独立的)。

I have a google form for data ingest which auto fills a series of forms needed to complete an application at my company.我有一个用于数据摄取的谷歌表单,它会自动填写在我公司完成申请所需的一系列表单。 Previously, you would have to manually input the data multiple times and I figured there had to be a better way.以前,您必须多次手动输入数据,我认为必须有更好的方法。

The code takes inputs from the google form via a spreadsheet so we can keep track and auto fills a 3 pre generated docs which later get synced on to our network drive so all in office can access what they need.该代码通过电子表格从 google 表单获取输入,因此我们可以跟踪并自动填充 3 个预先生成的文档,这些文档稍后会同步到我们的网络驱动器,以便办公室内的所有人都可以访问他们需要的内容。

Anyway, the code is as follows:无论如何,代码如下:

 function fileFills(e){ var address = e.values[1]; var tenman = e.values[2]; var tennum = e.values[3]; var price = e.values[4]; var wks = e.values[5]; var deposit = e.values[6]; var tname1 = e.values[7]; var tname2 = e.values[8]; var tname3 = e.values[9]; var tname4 = e.values[10]; var tname5 = e.values[11]; var tname6 = e.values[12]; var tname7 = e.values[13]; var tname8 = e.values[16]; var tname9 = e.values[17]; var file = DriveApp.getFileById('form template 1'); var parentFolder = DriveApp.getFolderById('main folder'); var newFolder = parentFolder.createFolder(address); var copy = file.makeCopy(address + ', ' + ' Summary'); copy.moveTo(newFolder); var doc = DocumentApp.openById(copy.getId()); var body = doc.getBody(); body.replaceText('{{Add}}', address); body.replaceText('{{TM}}', tenman); body.replaceText('{{TTC}}', tennum); body.replaceText('{{Price}}', price); body.replaceText('{{Time}}', wks); body.replaceText('{{Deposit}}', deposit); body.replaceText('{{N1}}', tname1); body.replaceText('{{N2}}', tname2); body.replaceText('{{N3}}', tname3); body.replaceText('{{N4}}', tname4); body.replaceText('{{N5}}', tname5); body.replaceText('{{N6}}', tname6); body.replaceText('{{N7}}', tname7); body.replaceText('{{N8}}', tname8); body.replaceText('{{N9}}', tname9); var file2 = DriveApp.getFileById('form template 2'); var copy2 = file2.makeCopy(address + ', ' + ' Key Sign'); copy2.moveTo(newFolder); var doc2 = DocumentApp.openById(copy2.getId()); var body2 = doc2.getBody(); body2.replaceText('{{Add}}', address); body2.replaceText('{{TTC}}', tennum); body2.replaceText('{{Time}}', wks); body2.replaceText('{{N1}}', tname1); body2.replaceText('{{N2}}', tname2); body2.replaceText('{{N3}}', tname3); body2.replaceText('{{N4}}', tname4); body2.replaceText('{{N5}}', tname5); body2.replaceText('{{N6}}', tname6); body2.replaceText('{{N7}}', tname7); body2.replaceText('{{N8}}', tname8); body2.replaceText('{{N9}}', tname9); var file3 = DriveApp.getFileById('form template 3'); var copy3 = file3.makeCopy(address + ', ' + ' Tenancy Summary'); copy3.moveTo(newFolder); var doc3 = DocumentApp.openById(copy.getId()); var body3 = doc3.getBody(); body3.replaceText('{{Add}}', address); body3.replaceText('{{TM}}', tenman); body3.replaceText('{{TTC}}', tennum); }

Obviously I have removed file and folder IDs above.显然我已经删除了上面的文件和文件夹 ID。

The issue is that when I submit a test result through the form, it generates a new folder with the correct address, it then copies the first doc into it and fills it, but that is as far as it gets.问题是,当我通过表单提交测试结果时,它会生成一个具有正确地址的新文件夹,然后将第一个文档复制到其中并填充它,但仅此而已。 I get no 2nd or 3rd form.我没有第二或第三种形式。

I had a version previously where I managed to get it to make copies of the 2nd and 3rd form as well, but only into the parent folder and it would not fill the data or move it to the correct folder.我以前有一个版本,我设法让它也复制了第二个和第三个表格,但只能复制到父文件夹中,它不会填充数据或将其移动到正确的文件夹中。

Please help!请帮忙! I am sure its something obvious that I'm missing but it's driving me crazy!我确信它有一些明显的东西我错过了,但它让我发疯了!

Thanks!谢谢!

var tname4 = e.values[10];
var tname5 = e.values[11];
var tname6 = e.values[12];
var tname7 = e.values[13];
var tname8 = e.values[16]; // <-- 14?
var tname9 = e.values[17]; // <-- 15?

I think the last two lines should be:我认为最后两行应该是:

var tname8 = e.values[14];
var tname9 = e.values[15];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM