执行信息

关于正在运行的脚本的信息

您可以通过 ExecutionInfo 对象的方法访问正在运行的脚本的某些属性。例如,isPreview() 会显示脚本当前是处于预览模式还是实际执行中。

这通常可以简化调试代码:

// Code that generates a report.
// ...
if (!AdsApp.getExecutionInfo().isPreview()) {
  // Do not email the report when in preview mode!
  MailApp.sendEmail("customer@example.com", "Report is ready!", report);
}

关于脚本账户的信息

通常需要获取正在运行的脚本的帐号信息,尤其是在多个帐号中使用相同的未更改脚本时更是如此。如果脚本通过电子邮件发出报告,收件人需要识别原始帐号。为此,您可以使用 Account 对象的 getCustomerId() 方法:

let accountId = AdsApp.currentAccount().getCustomerId();
MailApp.sendEmail("customer@example.com",
    "Report is ready for " + accountId, report);

Account 对象还提供了一些方法,可让您确定帐号的币种和时区。