Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Update for Dictionaries not working #123

Closed
javpla opened this issue Nov 11, 2016 · 7 comments
Closed

Contact Update for Dictionaries not working #123

javpla opened this issue Nov 11, 2016 · 7 comments
Assignees
Milestone

Comments

@javpla
Copy link

javpla commented Nov 11, 2016

Using Contact.Update() method to update fields that are stored in Dictionaries (e.g. EmailAddresses) does not actually update those fields in the server, even though the transaction is successful.
Using the same method to update other fields (e.g. JobTitle) succeeds to get the updates in the server as expected.

Server is running Exchange 2010 SP2.

The following code reflect the described behaviour using Nodejs :

var ews = require('ews-javascript-api');
ews.EwsLogging.DebugLogEnabled = false;

var ADMIN_USR = 'admin';
var USER = 'username';
var PWD = 'password';
var URL = 'exchange_server_url';

var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2010_SP2);
exch.Credentials = new ews.ExchangeCredentials(ADMIN_USR, PWD);
exch.Url = new ews.Uri(URL);

var userId = USER;
exch.ImpersonatedUserId = new ews.ImpersonatedUserId(ews.ConnectingIdType.SmtpAddress, userId);

var itemId = new ews.ItemId("AAMkADhlZDI5NjVmLTJlMTEtNDc4Yy04MjY3LWZjODA2NDYyM2M2NABGAAAAAAD6zwymntSnSZc2CLbI+SPhBwCCwiP5Mi5BTZxZKiwS2GujAAAA4eQoAACCwiP5Mi5BTZxZKiwS2GujAAAA5DiLAAA=");

updateContact();

function printProperties(contact) {
    // console.log(contact.propertyBag.properties.keys);
    console.log('GivenName: %s', contact.GivenName);
    if (contact.propertyBag.properties.objects.PhoneNumbers && contact.propertyBag.properties.objects.PhoneNumbers.entries) {
        console.log('PhoneNumbers Entries: \n%s', JSON.stringify(contact.propertyBag.properties.objects.PhoneNumbers.entries.objects));
    }
    if (contact.propertyBag.properties.objects.EmailAddresses && contact.propertyBag.properties.objects.EmailAddresses.entries) {
        console.log('EmailAddresses Entries: \n%s', JSON.stringify(contact.propertyBag.properties.objects.EmailAddresses.entries.objects));
    }
}

function updateContact() {
    ews.Contact.Bind(exch, itemId).then(function (contact) {
        console.log();
        console.log("OLD CONTACT:");
        printProperties(contact);

        contact.GivenName = "NEW Name";
        // update phone
        var key = ews.PhoneNumberKey.MobilePhone;
        var keyStr = 'MobilePhone';
        var phoneEntry = new ews.PhoneNumberEntry(keyStr, '111111111');
        contact.PhoneNumbers.Entries.set(ews.PhoneNumberKey.MobilePhone, phoneEntry);

        // update email
        var email = "new@email.com";
        var emailEntry1 = new ews.EmailAddressEntry('EmailAddress1', new ews.EmailAddress('home', email));
        contact.EmailAddresses.Entries.set(ews.EmailAddressKey.EmailAddress1, emailEntry1);

        contact.FileAsMapping = undefined; // FileAsMapping is not available in Exchange 2010

        console.log();
        console.log("UPDATING CONTACT:");
        printProperties(contact);

        // alt 1: UpdateContact
        contact.Update(ews.ConflictResolutionMode.AlwaysOverwrite).then(function () {
            ews.Contact.Bind(exch, itemId).then(function (contactUpdated) {
                console.log();
                console.log("UPDATED CONTACT:");
                printProperties(contactUpdated);
            }, function (err) {
                console.error(err);
            });
        }, function (err) {
            console.error(err);
        });
    }, function (err) {
        console.error(err);
    });
}

The console output:
(notice how emails and phone numbers are not changed whereas GivenName is)

OLD CONTACT:
GivenName: OLD Name
PhoneNumbers Entries: 
{"MobilePhone":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[null],"key":11,"phoneNumber":"000000000"}}
EmailAddresses Entries: 
{"EmailAddress1":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[null],"key":0,"emailAddress":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[null],"name":"other","address":"old@email.com","routingType":"SMTP","mailboxType":6,"id":null}}}

UPDATING CONTACT:
GivenName: NEW Name
PhoneNumbers Entries: 
{"MobilePhone":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[],"key":"MobilePhone","phoneNumber":"111111111"}}
EmailAddresses Entries: 
{"EmailAddress1":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[],"key":"EmailAddress1","emailAddress":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[null],"name":"home","address":"new@email.com","routingType":null,"mailboxType":null,"id":null}}}

UPDATED CONTACT:
GivenName: NEW Name
PhoneNumbers Entries: 
{"MobilePhone":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[null],"key":11,"phoneNumber":"000000000"}}
EmailAddresses Entries: 
{"EmailAddress1":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[null],"key":0,"emailAddress":{"___implementsInterface":["ISelfValidate","IJsonSerializable"],"___typeName":"ComplexProperty","Namespace":2,"OnChange":[null],"name":"other","address":"old@email.com","routingType":"SMTP","mailboxType":6,"id":null}}}````


@gautamsi
Copy link
Owner

do not use contact.EmailAddresses.Entries.set(ews.EmailAddressKey.EmailAddress1, emailEntry1);

use contact.EmailAddresses._setItem(ews.EmailAddressKey.EmailAddress1, emailEntry1);

jsdoc documentation of many classes are not updated (started porting jsdoc very late), the not all internal properties and classes are hidden in Typing. JavaScript based intellisense may still expose all the internal stuffs.

@javpla
Copy link
Author

javpla commented Nov 11, 2016

This worked for PhoneNumbers but not for EmailAddresses

@gautamsi
Copy link
Owner

I have to implement event delegation for changed or updates events. hopefully in a week or so.

@gautamsi
Copy link
Owner

can you try installing dev version and provide feedback. npm i ews-javascript-api@next.

there is a caveat in removing/replacing these entries, see the blog for more details

@javpla
Copy link
Author

javpla commented Dec 29, 2016 via email

@gautamsi
Copy link
Owner

gautamsi commented Dec 29, 2016

did you update the code I suggested contact.EmailAddresses._setItem(ews.EmailAddressKey.EmailAddress1, emailEntry1); similarly for Phone Number use contact.PhoneNumbers.__setItem(ews.PhoneNumberKey.MobilePhone, phoneEntry);

also, you can use any value for FileAsMapping it all values available in 2010 onward, I see your server is 2010_SP2. do not use undefined value for FileAsMapping. remove the line contact.FileAsMapping = undefined; // FileAsMapping is not available in Exchange 2010

@javpla
Copy link
Author

javpla commented Dec 29, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants