Execution info

Information about a running script

You can access certain attributes of a running script through the methods of the ExecutionInfo object. For example, isPreview() tells you whether a script is currently being previewed or is actually executing.

This often simplifies debugging code:

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

Information about a script's account

Account information for a running script is often needed, especially when the same unchanged script is used in multiple accounts. If the script is emailing out a report, the recipient needs to identify the originating account. You can use the Account object's getCustomerId() method for this:

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

The Account object also has methods to let you identify the account's currency and time zone.