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