Google Script Carrying over triggers when copying a spreadsheet

╄→гoц情女王★ 提交于 2019-12-12 02:06:21

问题


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) 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.

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.

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!


回答1:


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).

Some thing like...

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());
};


来源:https://stackoverflow.com/questions/13829918/google-script-carrying-over-triggers-when-copying-a-spreadsheet

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