1

我一直在尝试从为我们的大多数联系人定义的自定义字段中获取自定义值,但是我们没有从下面的脚本中获取任何数据,任何人都可以找出我的脚本哪里出错了。下面是我正在使用的示例脚本。

在下面的脚本中,我可以获得主要电子邮件值,但所有联系人的自定义字段值都是空白的,即使联系人中存在该值。

function GetContactDir() {

var All_Contacts = ContactsApp.getContacts();  

var email = new String();
var cust = new String();  
var Con_arr = new Array();

for (var i=0; i<All_Contacts.length; i++)
{

  email = "";
  email = All_Contacts[i].getPrimaryEmail();

  Con_arr = All_Contacts[i].getCustomFields("Organization ID");  //NOT WORKING

  if (!(email=="") && !(email==null) )
    Browser.msgBox(email + " **" + Con_arr[0] +  " ** " + String(i) ); 
}

}

问候, Saravana Kumar P.

4

1 回答 1

1

请试试这个:使用

`Con_arr = All_Contacts[i].getCustomFields();`  //without the string value

并替换你的行Browser.msgBox ...

有了这个 :

if(!(Con_arr.length==0)){Logger.log(email + " **" +Con_arr[0].getLabel()+" = "+Con_arr[0].getValue() )}; 

然后查看记录器(菜单>查看>日志)

编辑:这是完整的简化测试代码:

function GetContactDir() {

var All_Contacts = ContactsApp.getContacts();  

var email = '';
var cust = '';  
var Con_arr = new Array()

for (i=0; i<All_Contacts.length; i++){

  email = All_Contacts[i].getPrimaryEmail();

  Con_arr = All_Contacts[i].getCustomFields() ;  
  if (!(email=="") && !(email==null) )

    if(Con_arr.length>0){Logger.log(email + " **" +Con_arr[0].getLabel()+" = "+Con_arr[0].getValue() )}; 
}
}

EDIT2:让我们尝试以另一种方式解决问题,按自定义字段搜索:(请用有效值替换值)

function GetContact_test() {
var All_Contacts = ContactsApp.getContactsByCustomField('value of the field', 'name of the custom field');// note that the first term is a 'QUERY' so you don't need to give the entire ID, a single letter can bring results !
for(n=0;n<All_Contacts.length;++n){
Logger.log(n+'  '+All_Contacts[n].getFullName()); 
}
}
于 2012-06-23T15:02:28.057 回答