実行情報

実行中のスクリプトについての情報

実行中のスクリプトの特定の属性にアクセスするには、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 オブジェクトには、アカウントの通貨とタイムゾーンを識別できるメソッドもあります。