실행 정보

실행 중인 스크립트 정보

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 객체에는 계정의 통화와 시간대를 식별할 수 있는 메서드도 있습니다.