2012-11-19 62 views
4

我正在忙於編寫一些代碼,這些代碼將通過PHPEWS更新Microsoft Exchange服務器上的物理地址;使用PHP EWS更新聯繫人物理地址

但是對於我的生活我無法完全弄清楚如何更新物理地址,我可以更新除此之外的所有其他內容。

這是我的代碼。

// 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; 

我不斷收到以下錯誤多小時的反覆試驗,我終於算出來後,我自己

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 ())) 

希望有人能幫助

回答

5

這裏是代碼,

// 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; 

基本上你設置你的FieldURI和現場指數(一個必須記住,在更新時,你可以一次只更新一個項目),你會看到FieldURI被設置爲「聯繫人:PhysicalAddress:Street「這是因爲您一次只能更新一個項目。

接下來我們創建Contact標籤,然後創建PhysicalAddresses標籤,然後創建Entry標籤並將其設置爲Home的Key,最後我們設置Street標籤。

它創建的實際XML將如下所示。

<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> 

而這就是它,它然後更新街address.All你現在需要做的就是把代碼在一個循環,使用開關,看你想要的地址的一部分更新和鮑勃你叔叔。

噢,好希望這可以幫助某人。

+0

感謝Philip。自從上個3-4小時以來,我遇到了同樣的問題。你救了我。他們應該在某處顯示您需要逐一放置密鑰來更新它。 –