如何在创建新联系人时添加电子邮件地址和电话号码

时间:2018-03-09 18:48:37

标签: javascript ews-javascript-api

我使用ews-javascript-api来管理我的交换联系人。我可以创建一个联系人并添加一个给定名称和姓氏,但我尝试添加电子邮件地址或电话号码的所有内容都会导致异常被抛出。这就是我现在正在尝试的。

let number = {type: 2, value: "1234567890"};
let newContact          = new ews.Contact(window.exchangeService);
newContact.PhoneNumbers.entries.Add(number.type, number.value);

let address = {type: 0, value: "test@test.org"};
newContact.EmailAddresses.entries.Add(address.type, address.value);

我得到的例外......

TypeError: keyValuePair.value.WriteToXml is not a function
at EmailAddressDictionary../vendor/ews-javascript-api/js/ComplexProperties/DictionaryProperty.js.DictionaryProperty.WriteElementsToXml (DictionaryProperty.js:200)
at EmailAddressDictionary../vendor/ews-javascript-api/js/ComplexProperties/ComplexProperty.js.ComplexProperty.WriteToXml (ComplexProperty.js:109)
at EmailAddressDictionary../vendor/ews-javascript-api/js/ComplexProperties/DictionaryProperty.js.DictionaryProperty.WriteToXml (DictionaryProperty.js:213)
at ComplexPropertyDefinition../vendor/ews-javascript-api/js/PropertyDefinitions/ComplexPropertyDefinitionBase.js.ComplexPropertyDefinitionBase.WritePropertyValueToXml (ComplexPropertyDefinitionBase.js:101)
at PropertyBag../vendor/ews-javascript-api/js/Core/PropertyBag.js.PropertyBag.WriteToXml (PropertyBag.js:577)
at Contact../vendor/ews-javascript-api/js/Core/ServiceObjects/ServiceObject.js.ServiceObject.WriteToXml (ServiceObject.js:317)
at CreateItemRequest../vendor/ews-javascript-api/js/Core/Requests/CreateRequest.js.CreateRequest.WriteElementsToXml (CreateRequest.js:64)
at CreateItemRequest../vendor/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js.ServiceRequestBase.WriteBodyToXml (ServiceRequestBase.js:460)
at CreateItemRequest../vendor/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js.ServiceRequestBase.WriteToXml (ServiceRequestBase.js:529)
at CreateItemRequest../vendor/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js.ServiceRequestBase.EmitRequest (ServiceRequestBase.js:165)
at CreateItemRequest../vendor/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js.ServiceRequestBase.BuildXHR (ServiceRequestBase.js:131)
at SimpleServiceRequestBase.js:48
at Promise._execute (debuggability.js:300)
at Promise._resolveFromExecutor (promise.js:483)
at new Promise (promise.js:79)
at CreateItemRequest../vendor/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js.SimpleServiceRequestBase.InternalExecute (SimpleServiceRequestBase.js:47)
at MultiResponseServiceRequest.js:45
at Promise._execute (debuggability.js:300)
at Promise._resolveFromExecutor (promise.js:483)
at new Promise (promise.js:79)
at CreateItemRequest../vendor/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js.MultiResponseServiceRequest.Execute (MultiResponseServiceRequest.js:44)
at ExchangeService../vendor/ews-javascript-api/js/Core/ExchangeService.js.ExchangeService.InternalCreateItems (ExchangeService.js:690)
at ExchangeService../vendor/ews-javascript-api/js/Core/ExchangeService.js.ExchangeService.CreateItem (ExchangeService.js:484)
at Contact../vendor/ews-javascript-api/js/Core/ServiceObjects/Items/Item.js.Item.InternalCreate (Item.js:826)
at Contact../vendor/ews-javascript-api/js/Core/ServiceObjects/Items/Item.js.Item.Save (Item.js:907)
at Object.createContact [as @@ews/create-contact] (addressbook.js:81)
at createMiddleware.js:10
at createMiddleware.js:13
at fcs-spidr-silk-1.0.0.js:1901
at createMiddleware.js:13
at ContactsContainer._handleNewContact (contactsContainer.js:207)
at ContactsView.<anonymous> (contactsView.js:664)
at commitCallbacks (react-dom.development.js:6163)
at commitLifeCycles (react-dom.development.js:8784)
at commitAllLifeCycles (react-dom.development.js:9946)
at HTMLUnknownElement.callCallback (react-dom.development.js:542)
at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
at invokeGuardedCallback (react-dom.development.js:438)
at commitRoot (react-dom.development.js:10050)
at performWorkOnRoot (react-dom.development.js:11017)
at performWork (react-dom.development.js:10967)
at batchedUpdates (react-dom.development.js:11086)
at batchedUpdates (react-dom.development.js:2330)
at dispatchEvent (react-dom.development.js:3421)

1 个答案:

答案 0 :(得分:0)

设置这些项目的正确方法是contact.EmailAddresses._setItem(ews.EmailAddressKey.EmailAddress1, emailEntry1);

有关详细信息,请参阅https://github.com/gautamsi/ews-javascript-api/issues/123。另请参阅此博客,了解有关如何删除任何这些密钥的更多信息https://blogs.msdn.microsoft.com/emeamsgdev/2012/05/17/ews-managed-api-how-to-remove-email1-email2-email3-from-a-contact/