2016-07-26 95 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

找到它。由于某种原因,即使在联系人中定义了一个联系人,其中一个联系人也没有收到电子邮件。修正了它,错误消失了。