php-ews
php-ews copied to clipboard
Updating Tasks
Hello:
Can someone show me how to update a task. Right now here is what I'm doing:
$type_id = new \garethp\ews\API\Type\ItemIdType($this->external_id,$this->change_key);
$task = $api->getItem($type_id);
$bodyType = new \garethp\ews\API\Type\BodyType($this->description);
$request = [
'ItemChange' => [
'ItemId' => $type_id->toArray(),
'Updates' => [
'Body' => $bodyType->toArray(),
'DueDate' => $dt->toArray(),
'Subject' => $this->title,
]
]
];
$results = $api->updateItems($request);
And its not updating. Can someone point me in the right direction? Thanks!
You have to generate correct content to update Task.
$type_id = new \garethp\ews\API\Type\ItemIdType($this->external_id, $this->change_key);
$body = new BodyType();
$body->setBodyType(BodyTypeType::TEXT);
$body->set($this->description);
$changes = [
'Body' => $bodyType,
'StartDate' => (new \DateTime())->format('c'),
'DueDate' => (new \DateTime())->format('c')
];
$request = [
'ItemChange' => [
'ItemId' => $type_id->toArray(),
'Updates' => ItemUpdateBuilder::buildUpdateItemChanges('Task', 'task', $changes)
]
];
$options = [
'ConflictResolution' => ConflictResolutionType::ALWAYS_OVERWRITE,
];
/** @var TaskType $taskType */
$taskType = $this->getCalendar()->updateItems($request, $options)
`
This work only with subject, body and importance in my case:
If I put
$changes['StartDate'] = XXXX;
to the array I get the Error:
...Exception: Could not find uri item:startdate ...
If I i wrote:
$changes['task:StartDate'] = XXXX;
I get an array from buildUpdateItemChanges():
3:
FieldURI:
FieldURI: item:Sensitivity
Task:
Sensitivity: Normal
4:
IndexedFieldURI:
FieldURI:
FieldIndex: StartDate
Task:
task: 2018-10-12T14:51:46Z
Gives the following Message: PHP Fatal error: Uncaught SoapFault exception: [a:ErrorSchemaValidation] The request failed schema validation: The 'FieldURI' attribute is invalid - The value '' is invalid according to its datatype
If I don't use the field StartDate it works fine, all other fields from TASK throws the same exception. I'm very irritated, what I'm doing wrong?