Updating the physical address of contacts using PHP EWS

I am busy writing code that will update the physical address on the Microsoft exchange server through PHPEWS;

but for life I can’t figure out how to update the physical address, I can update everything else except this.

here is my code.

// Update Physical Address. $field = new EWSType_SetItemFieldType(); $field->IndexedFieldURI->FieldURI = 'contacts:PhysicalAddress:Street'; $field->IndexedFieldURI->FieldIndex = EWSType_PhysicalAddressKeyType::HOME; $field->Contact = new EWSType_ContactItemType(); $field->Contact->PhysicalAddress = new EWSType_PhysicalAddressDictionaryType(); $address = new EWSType_PhysicalAddressDictionaryEntryType(); $address->Key = EWSType_PhysicalAddressKeyType::HOME; $address->_ = $street; $field->Contact->PhysicalAddresses->Entry = $address; $change->Updates->SetItemField[] = $field; 

I keep getting the following error:

 Array ( [0] => stdClass Object ( [MessageText] => An object within a change description must contain one and only one property to modify. [ResponseCode] => ErrorIncorrectUpdatePropertyCount [DescriptiveLinkKey] => 0 [ResponseClass] => Error [Items] => stdClass Object ( ) ) ) 

hope someone can help

+4
source share
1 answer

after many hours of trial and error, I finally dealt with it myself.

here is the code

 // Update Physical Address. $field = new EWSType_SetItemFieldType(); $field->IndexedFieldURI->FieldURI = 'contacts:PhysicalAddress:Street'; $field->IndexedFieldURI->FieldIndex = EWSType_PhysicalAddressKeyType::HOME; $field->Contact = new EWSType_ContactItemType(); $field->Contact->PhysicalAddresses = new EWSType_PhysicalAddressDictionaryType(); $address = new EWSType_PhysicalAddressDictionaryEntryType(); $address->Key = EWSType_PhysicalAddressKeyType::HOME; $field->Contact->PhysicalAddresses->Entry = $address; $field->Contact->PhysicalAddresses->Entry->Street = $street; $change->Updates->SetItemField[] = $field; 

Basically you set your FieldURI and field index (you need to remember that when updating you can only update one element at a time) you will see that FieldURI is set to "contacts: PhysicalAddress: Street" because you can update one element at a time .

Next, we create the Contact tag, then the PhysicalAddresses tag, then the Entry tag and give it the key for the house, and finally we set the Street tag.

the actual generated XML will look something like this.

 <t:SetItemField> <t:IndexedFieldURI FieldURI="contacts:PhysicalAddress:CountryOrRegion" FieldIndex="Business" /> <t:Contact> <t:PhysicalAddresses> <t:Entry Key="Business"> <t:CountryOrRegion> </t:CountryOrRegion> </t:Entry> </t:PhysicalAddresses> </t:Contact> </t:SetItemField> 

And here he is, and then updates the street address. Now you need to make the code in a loop, use the switch to see which part of the address you want to update, and keep your uncle shut.

Oh well, that helps someone.

+5
source

Source: https://habr.com/ru/post/1446963/


All Articles