Google apps script 如何通过谷歌应用程序脚本从联系人中删除电子邮件字段
您可能会遇到暂时的服务问题,因为您的代码没有明显的错误。不过,您可以提高其效率并消除所有的删除/添加操作,这可能会降低出错的可能性 试试这个:Google apps script 如何通过谷歌应用程序脚本从联系人中删除电子邮件字段,google-apps-script,Google Apps Script,您可能会遇到暂时的服务问题,因为您的代码没有明显的错误。不过,您可以提高其效率并消除所有的删除/添加操作,这可能会降低出错的可能性 试试这个: Service error: ContactsApp: Entry does not have any fields set. (line 20, file "Code") /** *在oldDomain中查找所有具有电子邮件地址的联系人, *并在newDomain中将它们更改为相同的ID。 * *@param{String}oldDomain,例如'
Service error: ContactsApp: Entry does not have any fields set. (line 20, file "Code")
/**
*在oldDomain中查找所有具有电子邮件地址的联系人,
*并在newDomain中将它们更改为相同的ID。
*
*@param{String}oldDomain,例如'oldExample.com'
*@param{String}newDomain例如“newExample.org”
*
*@返回已更新联系人的{Number}计数。
*/
函数migrateDomain(旧域、新域){
//验证参数
if(arguments.length!==2)抛出新错误(“缺少参数”);
oldDomain='@'+oldDomain;
newDomain='@'+newDomain;
//检索在oldDomain中包含电子邮件的所有用户联系人
var contacts=ContactsApp.GetContactsByMailAddress(旧域);
Logger.log('num'+contacts.length);
对于(变量i=0;i for(var e=0;ethat工作得很好!谢谢。我想他们的Address()和Email()的名字把我弄糊涂了。干杯:)我也觉得很奇怪。emailField.setAddress
的文档中有一个街道地址的例子,这对我没有帮助!@GianPaJ:我注意到你对这个答案的编辑被拒绝了,但不应该被拒绝。(在评论中,你应该说你是问题的作者,并且你混淆了个人信息,这可能会影响到评论者。)不管怎样,我现在已经编辑了代码,使其更加通用。
Service error: ContactsApp: Entry does not have any fields set. (line 20, file "Code")
/**
* Find all contacts that have email addresses in the oldDomain,
* and change them to be the same ID in the newDomain.
*
* @param {String} oldDomain E.g. 'oldExample.com'
* @param {String} newDomain E.g. 'newExample.org'
*
* @returns {Number} Count of updated contacts.
*/
function migrateDomain(oldDomain, newDomain){
// Validate arguments
if (arguments.length !== 2) throw new Error( 'Missing arguments.');
oldDomain = '@' + oldDomain;
newDomain = '@' + newDomain;
// retrieve all the user's contacts that have email in oldDomain
var contacts = ContactsApp.getContactsByEmailAddress(oldDomain);
Logger.log('num '+contacts.length);
for (var i = 0; i < contacts.length; i++) {
var emails = contacts[i].getEmails();
Logger.log(emails.length+' emails');
for (var e=0; e<emails.length; e++) {
var email = emails[e].getAddress();
Logger.log(email);
if (email.indexOf(oldDomain) !== -1) {
// change
var newEmail = email.split("@")[0]+newDomain;
emails[e].setAddress(newEmail);
Logger.log(' changed to '+newEmail);
}
}
}
return i;
}