Reputation: 4566
I'm trying to update an EWS Contact object by removing EmailAddress1 and BusinessPhone.
I'm referencing this MSDN blog post that details how to do it for email. https://blogs.msdn.microsoft.com/emeamsgdev/2012/05/17/ews-managed-api-how-to-remove-email1-email2-email3-from-a-contact/
I think I've got it mostly figured out, but I can't figure out how to create the ExtendedPropertyDefinition for a group of ExtendedPropertyDefinition's. Here is the C# code from the blog post to do it.
ExtendedPropertyDefinition[] Email1PropertyGroup = new
ExtendedPropertyDefinition[5]{ PidLidEmail1DisplayName,
PidLidEmail1AddressType,
PidLidEmail1Address,
PidLidEmail1OriginalDisplayName,
PidLidEmail1OriginalEntryId};
And here is my attempt at the javascript equivalent
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 => {
But when I pass this emailPropertyGroup in my .Bind I get an exception. I can update my contact if I don't pass emailPropertyGroup and I only remove things like Surname, GivenName, etc.
In the successful Bind resolution I'm removing these properties with this code.
response.RemoveExtendedProperty(emailDisplayName);
response.RemoveExtendedProperty(emailAddressType);
response.RemoveExtendedProperty(emailAddress);
response.RemoveExtendedProperty(emailOriginalDisplayName);
response.RemoveExtendedProperty(emailOriginalEntryId);
However, I never reach this code as I get an exception as soon as I Bind. Here is the exception.
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
Also, are there constants defined for each extended property id? The blog post just passes in the raw hex values, such as 0x8080. Are these documented anywhere?
Upvotes: 0
Views: 213
Reputation: 1138
this is how you can create ExtendedPropertyDefinition Array properly
let emailPropertyGroup = [
emailDisplayName,
emailAddressType,
emailAddress,
emailOriginalDisplayName,
emailOriginalEntryId
];
you can then add this to propertyset like this
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
there is missing code in v 0.9.2 for ExtendedPropertyCollection class which lead to error even after you fix above code. I have published latest changes in @next ag on npm. this will be working with v 0.9.3-dev.1 in @next tag or in 0.9.3
Upvotes: 0
Reputation: 4566
Ok, got it figured out. I was creating a new ExtendedPropertyDefinition by passing the other ExtendedPropertyDefinition objects for each property as an array. Instead, now I'm creating a new PropertySet with those properties and that seems to work.
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 => {
Upvotes: 0
Reputation: 10224
According to the generated soap envelope, hex values are just hex encoded ids :
<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" />
The doc shows a constructor which takes a number in parameters, try replacing the hex by the corresponding number.
You can find the complete property list reference here : [MS-OXPROPS]: Exchange Server Protocols Master Property List
Upvotes: 0