locked
Contact.update EWS Managed API RRS feed

  • Question

  • Hi there,
    we've got problems trying to update contacs with the EWS Managed API.

    I tried to update a contacts postal adress with code coded like the example one in the MSDN (ee693004.aspx).
    The update function always returns an error ("An object within a change description must contain one and only one property to modify")
    Other Updates (surname, givenname, etc.) works fine.


    Can anyone tell me the right way to update postal adresses?

    My code:
            Dim Kont As Contact = Contact.Bind(service, itemid)
            Kont.PhysicalAddresses(PhysicalAddressKey.Business).Street = Straßegeschäftlich
            Kont.PhysicalAddresses(PhysicalAddressKey.Business).City = Ortgeschäftlich
            Kont.PhysicalAddresses(PhysicalAddressKey.Business).State = Regiongeschäftlich
            Kont.PhysicalAddresses(PhysicalAddressKey.Business).PostalCode = Postleitzahlgeschäftlich
            Kont.PhysicalAddresses(PhysicalAddressKey.Business).CountryOrRegion = Landgeschäftlich
            Kont.Update(ConflictResolutionMode.AlwaysOverwrite)
    
    

    EWS Version is 14.0.0.0

    Info from Exchange Management Console:
    Exchange Server 2007
    Microsoft Corporation
    Version: 08.01.0340.000

    Friday, February 26, 2010 8:13 AM

Answers

  • Edited to update:

     

    After experimenting with the 1.1 API, it turns out that you can clear a value from one of the DictionaryProperty fields by setting it to to null (or Nothing in VB.Net), eg, SomeExchContact.PhoneNumbers.Item(PhoneNumberKey.HomePhone) = Nothing

    Would have been nice if someone had pointed this out before, but at least it seems to be "fixed".

     

    Kirk

     

    • Edited by Kirkaiya Thursday, December 16, 2010 12:14 PM clarity.
    • Marked as answer by Matthias Sack Monday, January 17, 2011 2:26 PM
    Thursday, December 16, 2010 12:05 PM

All replies

  • Here is more info:

    I tried out both version of EWS (64 and 32 Bit) form this location:
    http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c3342fb3-fbcc-4127-becf-872c746840e1

    I think this should be the final version, right?
    in Visual Studio it is shown with the Version number 14.0.0.0 looking at the dll-file directly it shows 14.0.650.7

    I also tried out my program on another Exchange Server (2007 SP2) but the problem/error is the same.

    Is there anybody who can help me?

    Kind regards Matthias
    Tuesday, March 2, 2010 10:55 AM
  • Are you using the final version of the EWS Managed API?
    David Claux | Program Manager - Exchange Web Services

    Hi David,
    following the download link the downloadable version of EWS Managed API should be 14.0.650.8 after downloading and installing the API the properties of the .dll File shows a version 14.0.650.7, is this right?
    If I add this .dll to my references in VS2008 the displayed version is 14.0.0.0. Is this a display error in VS or am I doing something wrong?
    Wednesday, March 3, 2010 8:03 AM
  • Hi there again,

    I've found the problem using the code above. If on of the Variables is empty, the update fuction crashes with the error.

    But now I've got another problem: How can I set an updatevalue to an empty string?

    I tried out these code sniples, but all of them leading to the error above:
    Kont.PhysicalAddresses(PhysicalAddressKey.Business).City = ""
    Kont.PhysicalAddresses(PhysicalAddressKey.Business).City = nothing
    Kont.PhysicalAddresses(PhysicalAddressKey.Business).City = " "
    Kont.PhysicalAddresses(PhysicalAddressKey.Business).City = string.empty

    The same error occures trying to update Phonenumbers.

     
    Wednesday, March 3, 2010 2:29 PM
  • Matthias,

    You are using the right version of the API.

    Have you tried setting City to null?

    FYI, this bug will be fixed in the next release of the API.
    David Claux | Program Manager - Exchange Web Services
    Wednesday, March 3, 2010 7:16 PM
  • i'm using the powershell, and for string values like companyName, it works with

    $contact.CompanyName = $null  to clear the value.

    but i have the same problem, unable to clear a phone number or address. tried:

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]=$null

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]=[System.String]::Empty

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]=""

    all with error when updating (in german, translation is like :exception calling update with 1 arguments: an object with an update description shoul only contain exactly one property to change)

    however,

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]="12345"

    changes the value to 12345 as expected.

    should there be a method like clear() or remove(index) or so ?? how can one remove a businessphone or streetaddress ????

    Wednesday, April 14, 2010 7:03 PM
  • i'm using the powershell, and for string values like companyName, it works with

    $contact.CompanyName = $null  to clear the value.

    but i have the same problem, unable to clear a phone number or address. tried:

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]=$null

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]=[System.String]::Empty

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]=""

    all with error when updating (in german, translation is like :exception calling update with 1 arguments: an object with an update description shoul only contain exactly one property to change)

    however,

    $contact.Phonenumbers[[Microsoft.Exchange.webservices.Data.PhoneNumberKey]::BusinessPhone]="12345"

    changes the value to 12345 as expected.

    should there be a method like clear() or remove(index) or so ?? how can one remove a businessphone or streetaddress ????


    to answer my own question and maybe to solve the problem:

    it is definitely so that the xml code generated when assigning $null or empty string to one of the collection items (PhoneNumbers, Address,..) is wrong, it looks like

        #          <t:SetItemField>
        #            <t:IndexedFieldURI FieldURI="contacts:PhoneNumber" FieldIndex="BusinessPhone" />
        #            <t:Contact>
        #              <t:PhoneNumbers>
        #                <t:Entry Key="BusinessPhone">
        #                </t:Entry>
        #              </t:PhoneNumbers>
        #            </t:Contact>
        #          </t:SetItemField>

    and should look like

    <t:DeleteItemField>             
      <t:IndexedFieldURI FieldURI="contacts:PhoneNumber" FieldIndex="BusinessPhone" />
    </t:DeleteItemField>

    but with the help of luke brennan and his blog, where he showed how to clear a email address, i solved my problem. you have to update or save the contact, but avoid assigning empty values to one og these fields, but clear some extended properties afterwards instead. with powershell, removing the business phone entry looks like:

    $PidTagBusinessTelephoneNumber = 14856
    $PidLidWorkAddressStreet = 32837

    $objPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)
    $objPropertySet.add( (new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition($PidTagBusinessTelephoneNumber, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String) ) )
    $objPropertySet.add( (new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,$PidLidWorkAddressStreet, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String) ) )

    $newcontact=[Microsoft.Exchange.WebServices.Data.Contact]::Bind($service,$Item.Id,objPropertySet)
    $newContact.RemoveExtendedProperty( (new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition($PidTagBusinessTelephoneNumber, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String) ) )
    $newContact.RemoveExtendedProperty( (new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,$PidLidWorkAddressStreet, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String) ) )

    $newcontact.update([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AlwaysOverwrite)


    my major problem was to find the extended properties, but with ews editor you can display all known extended properties. to make it a little bit difficult, some are of defaultpropertyset::address and some are only extendedproperties (see the code above, businessphone is extendedproperty, workstreetaddress is address propertyset).  and to make it even more boring, the names are different. the work street address property is named WorkAddressStreet and is defaultpropertyset::address, and the home street address is named HomeAddressStreetAddress and is extended property.

    following the extended properties i used (most common fields)

    $PidTagBusinessTelephoneNumber = 14856
    $PidTagHomeTelephoneNumber = 14857
    $PidTagmobileTelephoneNumber = 14876
    $PidTagRadioTelephoneNumber = 14877
    $PidTagCarTelephoneNumber = 14878
    $PidTagOtherTelephoneNumber = 14879
    $PidTagBusinessFaxNumber = 14884
    $PidTagHomeFaxNumber = 14885
    $PidTagCountry = 14886
    $PidTagStateOrProvince = 14888
    $PidTagStreetAddress = 14889
    $PidTagPostalCode = 14890
    $PidTagPostOfficeBox = 14891
    $PidTagLocality = 14887
    $PidTagHomeAddressCity = 14937
    $PidTagHomeAddressCountry = 14938
    $PidTagHomeAddressPostalCode = 14939
    $PidTagHomeAddressStateOrProvince = 14940
    $PidTagHomeAddressStreetAddress = 14941
    $PidTagHomeAddressPostOfficeBox = 14942
    $PidTagOtherAddressCity = 14943
    $PidTagOtherAddressCountry = 14944
    $PidTagOtherAddressPostalCode = 14945
    $PidTagOtherAddressStateOrProvince = 14946
    $PidTagOtherAddressStreetAddress = 14947
    $PidTagOtherAddressPostOfficeBox = 14948
    $PidLidWorkAddressStreet = 32837
    $PidLidWorkAddressCity = 32838
    $PidLidWorkAddressState = 32839
    $PidLidWorkAddressPostalCode = 32840
    $PidLidWorkAddressCountry = 32841
    $PidLidWorkAddressPostOfficeBox = 32842

    you may look at luke's blog because it's his idea

    https://blogs.technet.com/lukeb/archive/2010/01/12/powershell-and-ews-how-to-update-contacts.aspx 

    Friday, April 16, 2010 4:37 PM
  • HI all. Is this still only way to clear dictionary fields?

    Friday, June 25, 2010 12:21 AM
  • Edited to update:

     

    After experimenting with the 1.1 API, it turns out that you can clear a value from one of the DictionaryProperty fields by setting it to to null (or Nothing in VB.Net), eg, SomeExchContact.PhoneNumbers.Item(PhoneNumberKey.HomePhone) = Nothing

    Would have been nice if someone had pointed this out before, but at least it seems to be "fixed".

     

    Kirk

     

    • Edited by Kirkaiya Thursday, December 16, 2010 12:14 PM clarity.
    • Marked as answer by Matthias Sack Monday, January 17, 2011 2:26 PM
    Thursday, December 16, 2010 12:05 PM
  • Seems to work now, thanks.
    Monday, January 17, 2011 2:26 PM
  • Not all fields work this way.

    I am attempting to null out the Email1 field(s), with no luck.

     

    I am binding to an existing contact using the ItemID. I then want to update the contact after setting each of its properties. I have tried setting the:

     

    Dim email As New EmailAddress
    
    email.Address = nothing
    email.Name = nothing
    
    contact.EmailAddresses(EmailAddressKey.EmailAddress1) = email

    Calling the contact.Update throws an error: " An object within a change description must contain one and only one property to modify"

     

    How can I set the email fields to nothing, null, blank, when they had a value previously?

     


    Thanks Rob
    Monday, January 31, 2011 6:38 PM
  • hi Elfmanne,

    I am facing the same problem with api 1.1.

    Have you found a solution yet?

    thanks.


    Zay Yar
    Friday, August 5, 2011 9:48 AM