jamesiarmes / php-ews

PHP Exchange Web Services
http://jamesarmes.com/php-ews/
MIT License
567 stars 304 forks source link

Update contact notes (BodyType) #321

Open Leenzur opened 8 years ago

Leenzur commented 8 years ago

Hi everyone ! First thanks for this awesome library ! We are using php-ews to develop some functionnalities like synchronize contacts with our company's web application under Symphony2. Everything works fine, I'm starting to understand how exchange request are made but even if I can read Contacts Notes due to documentation, I don't find any code which explain how update theses. Here is my code for the moment :

$request = new UpdateItemType();

$request->SendMeetingInvitationsOrCancellations = 'SendToNone';
$request->MessageDisposition = 'SaveOnly';
$request->ConflictResolution = 'AlwaysOverwrite';
$request->ItemChanges = array();

// Build out item change request.
$change = new ItemChangeType();
$change->ItemId = new ItemIdType();
$change->ItemId->Id = $exchangeContact->getItemId();
$change->ItemId->ChangeKey = $exchangeContact->getChangeKey();
$change->Updates = new NonEmptyArrayOfItemChangeDescriptionsType();
$change->Updates->SetItemField = array(); // Array of fields to be update
$change->Updates->DeleteItemField = array(); // Array of fields to be removed

// -- Notes update
$notes = '
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="Generator" content="Microsoft Exchange Server">
        <!-- converted from rtf -->
        <style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
    </head>
    <body>
        <font face="Calibri" size="2">
            <span style="font-size:11pt;">
                <div>Commentaire sur notre monsieur test 2</div>
                <div>&nbsp;</div>
            </span>
        </font>
    </body>
</html>
';
$field = new SetItemFieldType();
$field->ExtendedFieldURI = new PathToExtendedFieldType();
$field->ExtendedFieldURI->FieldURI = 'contacts:Notes';
$field->ExtendedFieldURI->FieldIndex = BodyTypeType::HTML;
$field->Contact = new ContactItemType();
$ews_body = new BodyType();
$ews_body->BodyType = BodyTypeType::HTML;
$ews_body->_ = $notes;
$field->Contact->ExtendedProperty[] = $ews_body;
$change->Updates->SetItemField[] = $field;

// Set all changes
$request->ItemChanges[] = $change;

// Send request
$result = $this->exchangeManager->getConnection()->UpdateItem($request);

Error is : _SOAP-ERROR: Encoding: object has no 'ExtendedFieldURI' property 500 Internal Server Error - SoapFault _ Because I'm trying to access Body property by ExtendedFieldURI for the moment.

Thanks for your help.

jamesiarmes commented 7 years ago

You can use $field->FieldURI to set the contact notes. For example:

$field = new SetItemFieldType();
$field->FieldURI = new PathToUnindexedFieldType();
$field->FieldURI->FieldURI = new UnindexedFieldURIType();
$field->FieldURI->FieldURI->_ = UnindexedFieldURIType::ITEM_BODY;

$field->Contact = new ContactItemType();
$field->Contact->Body = new BodyType();
$field->Contact->Body->_ = $body;
$field->Contact->Body->BodyType = new BodyTypeType();;
$field->Contact->Body->BodyType->_ = BodyTypeType::HTML;

$change->Updates->SetItemField[] = $field;
nagesh314 commented 7 years ago

how to get contact notes data using full sync. its doesnt show when I do ALL_PROPERTIES.

jamesiarmes commented 7 years ago

@nagesh314 Exchange does not include the body fields (along with various others) in a FindItem request. You will need to issue a separate GetItem request in order to get these fields; you can make a single request to get the details of multiple items.

If you have further issues with this, please open a new issue as your question does not pertain to the original issue here.