2016-07-26 96 views
0

我有一個通常運行正常的觸發腳本,但是,它現在在getAddress()上引發一個未定義的錯誤。下面的代碼:ContactApp突然返回undefined

var churnGroup = ContactsApp.getContactGroup("Churn"); 
    var churnGroupContacts = churnGroup.getContacts(); 


    for(var m=0;m<churnGroupContacts.length;m++){ 
    var CME = churnGroupContacts[m].getEmails(); //<---TypeError: Cannot call method "getAddress" of undefined is being triggered on this line 
    var emailTo = CME[0].getAddress(); 
    var emailSubject = "Daily Churn Report"; 
    MailApp.sendEmail({ 
    to: emailTo, 
    subject: emailSubject, 
    htmlBody: emailBody, 
    inlineImages:emailImages}); 
    } 

} 

有任何形式的限制與ContactApp變化?謝謝

+0

嘗試Logger.log(CME);看看打印什麼數據 –

回答

0

請嘗試添加try catch語句。

try { 
    // your script code here 
} catch(e) { 
    // if the script code throws an error, 
    // do something with the error here 
} 

其實,有實例,其中應用腳本錯誤正在通過簡單地添加異常處理截取和處理。如

  • Issue 5579在谷歌 - 應用程序 - 腳本的問題跟蹤
  • ​​

我希望幫助。

0

找到它。由於某種原因,即使在聯繫人中定義了一個聯繫人,其中一個聯繫人也沒有收到電子郵件。修正了它,錯誤消失了。