无法通过Google Apps脚本向联系人添加地址[已解决] [英] Unable to add an address to a Contact via Google Apps Script [SOLVED]

查看:54
本文介绍了无法通过Google Apps脚本向联系人添加地址[已解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过Google Apps脚本创建联系人,并添加电话号码,但是我无法添加地址,并收到错误消息找不到您请求的资源."

I can create a Contact via Google Apps Script, and add a phone number but I've been unable to add an address, getting an error "The resource you requested could not be located."

注意:fName,actualLastName,电子邮件,地址& phone1都是字符串

Note: fName, actualLastName, email, address & phone1 are all strings

//  create the Contact
var newContact = ContactsApp.createContact(fName, actualLastName, email);
var newName = newContact.getFullName();
Logger.log("newName: " + newName);
Logger.log("New contact added");



//  attempt to add the address - DOESN'T WORK
try {
  Logger.log("Wanting to add this address: ", address);
  newContact.addAddress(ContactsApp.Field.WORK_ADDRESS, address);  
  Logger.log("Address added");
} catch(err) {
  Logger.log("Stumbled while trying to add address: " + err.message);
  Browser.msgBox("Stumbled while trying to add address to contact");
}

记录的错误消息是:尝试添加地址时信息出错:找不到所需的资源."

The logged error message is: "Info Stumbled while trying to add address: The resource you requested could not be located."

添加电话号码可以正常工作:

Adding a phone number works fine:

newContact.addPhone(ContactsApp.Field.MOBILE_PHONE, phone1);

然后联系人被添加到适当的组:

And the Contact gets added to the appropriate Group:

var group = ContactsApp.getContactGroup("System Group: My Contacts");
group.addContact(newContact);

推荐答案

作为一种解决方法,我想提出以下修改.在此修改中,创建联系人时将检索联系人ID.并且,addPhoneaddAddress用于通过联系人ID检索联系人对象.

As one workaround, I would like to propose the following modification. In this modification, the contact ID is retrieved when the contact is created. And, addPhone and addAddress are used for the contact object retrieving with the contact ID.

var newContact = ContactsApp.createContact(fName, actualLastName, email);
var contactId = newContact.getId();
var c = ContactsApp.getContactById(contactId);
c.addAddress(ContactsApp.Field.WORK_ADDRESS, address);

参考:

  • getContactById(id)
  • Reference:

    • getContactById(id)
    • 这篇关于无法通过Google Apps脚本向联系人添加地址[已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆