复制电子表格时的Google脚本继承触发器 [英] Google Script Carrying over triggers when copying a spreadsheet

查看:91
本文介绍了复制电子表格时的Google脚本继承触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在为我的工作开发一个项目.我们正在使用Google云端硬盘来跟踪工作订单.这是怎么回事:

Okay, so I'm working on a project for my job. We're using Google Drive to track work orders. Here's how it goes:

1)您填写描述工作订单的请求表. 2)Google脚本将生成的信息从请求表单"转换为请求报告"并创建跟踪表单 3)通过填写跟踪表来在工作单上签字.

1) You fill out Request Form describing your work order. 2) Google scripts turns generates info from Request Form into Request Report and creates an Tracking Form 3) Personnel sign off on work order by filling out Tracking Form.

非常简单,但这是麻烦.我最初将所有工作订单合并到一个电子表格中,您会输入工作订单的ID,但是人们总是在输入正确的#时犯错误,因此我的老板希望每个工作订单都拥有自己的单独的跟踪表.一旦实施了这一新流程,她希望我尽可能少地参与其中.

Pretty simple, but here's the trouble. I originally had all the Work Orders consolidated on one spreadsheet and you would input the Work Order's ID, but people kept making mistakes putting the correct # in so my boss wants each work order to have it's own separate Tracking Form. And once this new process is implemented, she wants me to touch it as little as possible.

麻烦来了,在这里,我使用了一个包含所有Google脚本代码的跟踪表单模板,但是触发器无法复制.我尝试使用请求表单"代码运行跟踪表单"代码,但是它太复杂且容易出错.我尝试将onOpen代码(将为Project Manager创建菜单以授权触发器)写入模板,希望它可以复制过来,但这也不起作用.

Here's where the trouble comes in, I use a Tracking Form Template that has all the Google Script code in it, but the triggers can't copy over. I tried using the Request Form code to run the Tracking Form code, but it's way too complicated and prone to errors. I tried writing an onOpen code (that would create a menu for the Project Manager to authorize triggers) into the Template with the hope it would copy over, but that doesn't work either.

有人可以告诉我如何解决此问题吗?谢谢!

Can someone PLEASE tell me how to work around this problem?? Thanks!

推荐答案

在创建电子表格/脚本的新副本时,通过资源"菜单创建的触发器不会停留在该触发器中.认为您要以编程方式创建它们,那么它们(仍然需要运行功能并进行授权).

Triggers that are created through the Resource menu won't stay in when a new copy of the spreadsheet / script is made. Think you'll want to create them programmatically, then they will (still need to run a function for it and authorize).

类似...

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ScriptApp.newTrigger('logDate').forSpreadsheet(ss).onFormSubmit().create();
}

function logDate() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName('Sheet1');
  s.getRange('A1').setValue(new Date());
};

这篇关于复制电子表格时的Google脚本继承触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆