実行情報

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

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