无法从EWS联系人对象中删除电子邮件或电话号码

时间:2018-03-15 17:43:51

标签: ews-javascript-api

我正在尝试通过删除EmailAddress1和BusinessPhone来更新EWS联系人对象。

我正在引用此MSDN博客文章,详细说明如何为电子邮件执行此操作。 https://blogs.msdn.microsoft.com/emeamsgdev/2012/05/17/ews-managed-api-how-to-remove-email1-email2-email3-from-a-contact/

我想我已经弄明白了,但我无法弄清楚如何为一组ExtendedPropertyDefinition创建ExtendedPropertyDefinition。以下是博客文章中的C#代码。

ExtendedPropertyDefinition[] Email1PropertyGroup = new 
  ExtendedPropertyDefinition[5]{ PidLidEmail1DisplayName, 
    PidLidEmail1AddressType, 
    PidLidEmail1Address, 
    PidLidEmail1OriginalDisplayName, 
    PidLidEmail1OriginalEntryId};

这是我对javascript等效的尝试

const emailDisplayName          = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8080, ews.MapiPropertyType.String);
const emailAddressType          = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8082, ews.MapiPropertyType.String);
const emailAddress              = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8083, ews.MapiPropertyType.String);
const emailOriginalDisplayName  = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8084, ews.MapiPropertyType.String);
const emailOriginalEntryId      = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8085, ews.MapiPropertyType.Binary);
const emailPropertyGroup = 
  new ews.ExtendedPropertyDefinition([emailDisplayName, 
                                      emailAddressType, 
                                      emailAddress, 
                                      emailOriginalDisplayName, 
                                      emailOriginalEntryId]);
const updatedContact = 
  ews.Contact.Bind(window.exchangeService, 
                   ewsId, 
                   emailPropertyGroup).then(response => {

但是当我在.Bind中传递这个emailPropertyGroup时,我得到一个例外。如果我没有通过emailPropertyGroup,我可以更新我的联系人,我只删除Surname,GivenName等内容。

在成功的Bind解析中,我正在使用此代码删除这些属性。

response.RemoveExtendedProperty(emailDisplayName);
response.RemoveExtendedProperty(emailAddressType);
response.RemoveExtendedProperty(emailAddress);                  
response.RemoveExtendedProperty(emailOriginalDisplayName);            
response.RemoveExtendedProperty(emailOriginalEntryId);

然而,我从未达到此代码,因为我在绑定后立即获得异常。这是例外。

debuggability.js:870 [31mUnhandled rejection TypeError: this.PropertySet.Contains is not a function
at GetItemRequest.get [as EmitTimeZoneHeader] (https://sr1.genband.com/genlync/bundle-electron.js:136846:37)
at GetItemRequest../vendor/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js.ServiceRequestBase.WriteToXml (https://sr1.genband.com/genlync/bundle-electron.js:140968:111)
at GetItemRequest../vendor/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js.ServiceRequestBase.EmitRequest (https://sr1.genband.com/genlync/bundle-electron.js:140642:18)
at GetItemRequest../vendor/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js.ServiceRequestBase.BuildXHR (https://sr1.genband.com/genlync/bundle-electron.js:140608:14)
at https://sr1.genband.com/genlync/bundle-electron.js:141665:33
at Promise._execute (https://sr1.genband.com/genlync/bundle-electron.js:2238:9)
at Promise._resolveFromExecutor (https://sr1.genband.com/genlync/bundle-electron.js:4593:18)
at new Promise (https://sr1.genband.com/genlync/bundle-electron.js:4189:10)
at GetItemRequest../vendor/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js.SimpleServiceRequestBase.InternalExecute (https://sr1.genband.com/genlync/bundle-electron.js:141664:16)
at https://sr1.genband.com/genlync/bundle-electron.js:139547:19
at Promise._execute (https://sr1.genband.com/genlync/bundle-electron.js:2238:9)
at Promise._resolveFromExecutor (https://sr1.genband.com/genlync/bundle-electron.js:4593:18)
at new Promise (https://sr1.genband.com/genlync/bundle-electron.js:4189:10)
at GetItemRequest../vendor/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js.MultiResponseServiceRequest.Execute (https://sr1.genband.com/genlync/bundle-electron.js:139546:16)
at ExchangeService../vendor/ews-javascript-api/js/Core/ExchangeService.js.ExchangeService.InternalBindToItems (https://sr1.genband.com/genlync/bundle-electron.js:128751:24)
at ExchangeService../vendor/ews-javascript-api/js/Core/ExchangeService.js.ExchangeService.BindToItem (https://sr1.genband.com/genlync/bundle-electron.js:128533:21)
at Function../vendor/ews-javascript-api/js/Core/ServiceObjects/Items/Contact.js.Contact.Bind (https://sr1.genband.com/genlync/bundle-electron.js:150740:24)
at Object.updateContact [as @@ews/update-addressbook] (https://sr1.genband.com/genlync/bundle-electron.js:90551:90)
at https://sr1.genband.com/genlync/bundle-electron.js:90889:46
at https://sr1.genband.com/genlync/bundle-electron.js:91653:24
at https://sr1.genband.com/genlync/bundle-electron.js:189169:291
at https://sr1.genband.com/genlync/bundle-electron.js:90997:24
at ContactsContainer._handleUpdateContact (https://sr1.genband.com/genlync/bundle-electron.js:71762:17)
at ContactsView._handleEditContactModalSave (https://sr1.genband.com/genlync/bundle-electron.js:72656:17)
at ModalCreateEditPABContactView.<anonymous> (https://sr1.genband.com/genlync/bundle-electron.js:81774:28)
at commitCallbacks (https://sr1.genband.com/genlync/bundle-electron.js:44319:15)
at commitLifeCycles (https://sr1.genband.com/genlync/bundle-electron.js:46940:13)
at commitAllLifeCycles (https://sr1.genband.com/genlync/bundle-electron.js:48102:9)
at HTMLUnknownElement.callCallback (https://sr1.genband.com/genlync/bundle-electron.js:38698:14)
at Object.invokeGuardedCallbackDev (https://sr1.genband.com/genlync/bundle-electron.js:38737:16)
at invokeGuardedCallback (https://sr1.genband.com/genlync/bundle-electron.js:38594:27)
at commitRoot (https://sr1.genband.com/genlync/bundle-electron.js:48206:9)
at performWorkOnRoot (https://sr1.genband.com/genlync/bundle-electron.js:49173:42)
at performWork (https://sr1.genband.com/genlync/bundle-electron.js:49123:7)
at batchedUpdates (https://sr1.genband.com/genlync/bundle-electron.js:49242:9)
at batchedUpdates (https://sr1.genband.com/genlync/bundle-electron.js:40486:12)
at dispatchEvent (https://sr1.genband.com/genlync/bundle-electron.js:41577:5)[0m

此外,是否为每个扩展属性ID定义了常量?博客文章只传入原始十六进制值,例如0x8080。这些记录在哪里吗?

3 个答案:

答案 0 :(得分:0)

根据生成的soap信封,十六进制值只是十六进制编码的id:

<t:ExtendedFieldURI DistinguishedPropertySetId="Address" PropertyId="32896" PropertyType="String" />
<t:ExtendedFieldURI DistinguishedPropertySetId="Address" PropertyId="32898" PropertyType="String" />
<t:ExtendedFieldURI DistinguishedPropertySetId="Address" PropertyId="32899" PropertyType="String" />
<t:ExtendedFieldURI DistinguishedPropertySetId="Address" PropertyId="32900" PropertyType="String" />
<t:ExtendedFieldURI DistinguishedPropertySetId="Address" PropertyId="32901" PropertyType="Binary" />

doc显示一个构造函数,该构造函数接受参数中的数字,尝试用相应的数字替换十六进制。

您可以在此处找到完整的属性列表参考:[MS-OXPROPS]: Exchange Server Protocols Master Property List

答案 1 :(得分:0)

好的,明白了。我通过将每个属性的其他ExtendedPropertyDefinition对象作为数组传递来创建新的ExtendedPropertyDefinition。相反,现在我正在创建一个具有这些属性的新PropertySet,这似乎有效。

    const emailDisplayName          = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8080, ews.MapiPropertyType.String);
    const emailAddressType          = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8082, ews.MapiPropertyType.String);
    const emailAddress              = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8083, ews.MapiPropertyType.String);
    const emailOriginalDisplayName  = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8084, ews.MapiPropertyType.String);
    const emailOriginalEntryId      = new ews.ExtendedPropertyDefinition(ews.DefaultExtendedPropertySet.Address, 0x8085, ews.MapiPropertyType.Binary);

    const emailPropertyGroup        = new ews.PropertySet(ews.BasePropertySet.FirstClassProperties, [emailDisplayName, emailAddressType, emailAddress, emailOriginalDisplayName, emailOriginalEntryId]);

    const updatedContact = ews.Contact.Bind(window.exchangeService, ewsId, emailPropertyGroup).then(response => {

答案 2 :(得分:0)

这是你可以正确创建ExtendedPropertyDefinition数组的方法

let emailPropertyGroup = [
    emailDisplayName,
    emailAddressType,
    emailAddress,
    emailOriginalDisplayName,
    emailOriginalEntryId
];

然后你可以像这样将

添加到属性集中
let props = new PropertySet(BasePropertySet.IdOnly);
props.Add(ContactSchema.DisplayName);
props.Add(ContactSchema.GivenName);
props.Add(ContactSchema.EmailAddresses);
props.Add(ContactSchema.EmailAddress1);
props.AddRange(emailPropertyGroup); // this line

对于ExtendedPropertyCollection类,v 0.9.2中缺少代码,即使在修复上述代码后也会导致错误。我在npm上发布了@next ag的最新更改。这将适用于@next标签或0.9.3

中的v 0.9.3-dev.1