有没有办法在脚本所有者的授权下运行google docs脚本?

Is there a way to run google docs script under the script owner's authorization?

本文关键字:脚本 运行 google docs 授权 所有者 有没有      更新时间:2023-09-26

我有一个谷歌表,这是由一些经销商输入的订单的主数据库。因此,此母版工作表必须具有有限的编辑访问权限。我想创建一些其他的表(一个为每个经销商),通过他们可以输入订单,并添加到我的主表通过脚本运行在这些表。这可能吗?当我试着这样做的时候,它拒绝他们访问主表。有办法解决这个问题吗?

我用来解决这个问题的一个方法是设置一个可安装的触发器以固定的时间间隔运行。

可安装触发器在触发器的所有者权限上运行,因此它将能够访问主电子表格以及每个经销商的电子表格。诀窍是为一个函数分配一个定时触发器,该函数检查每个经销商的表格是否更新,然后对主电子表格进行适当的更改。您需要确保触发器运行的时间不会太长,也不会太频繁,因为您每天的脚本运行时间有限。

类似如下:

function myTrigger() {
  var time = new Date();
  // maybe check to see if it's night or other times that dealers won't update
  // that way you can return early and don't waste quota hours
  var dealerSpreadsheetIds = ["id1", "id2", ...];
  var dealerSheetName = "Deals";
  for (var i = 0; i < dealerSpreadsheetIds.length; i++) {
    var sheet = SpreadsheetApp.openById(dealerSpreadsheetIds[i]).getSheetByName(dealerSheetName);
    // check Deals sheet ranges for updates
    // if there is an update, update the main spreadsheet
  }
}