Open Wirbelrind opened 5 years ago
Hi @Wirbelrind
requiredattendees
(and any other similar fields) are arrays of ActivityParty
records (see here).
I believe you have to set those before create the appointment as per C# sample. Try something like
$party = $client->entity('activityparty');
$party->partyid = new EntityReference ('systemuser', $systemuserid);
...
$appointment->requiredattendees = [ $party ];
$appointment->organizer = [ $party ];
$appointmentID = $appointment->create();
HTH George
The error messages are now fixed but the data in activity party are still not registered.
At the table level I can see that the appointment is created, owner is set accordingly. But neither the organizer nor the required people.
Any other ideas where the problem could be?
Wirbelrind
Hi @Wirbelrind
can you paste the full code creating the subscription please?
Thanks George
@georged
Here is our complete test code
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
use AlexaCRM\CRMToolkit\Client;
use AlexaCRM\CRMToolkit\Entity;
use AlexaCRM\CRMToolkit\Entity\EntityReference;
use AlexaCRM\CRMToolkit\Entity\MetadataCollection;
use AlexaCRM\CRMToolkit\Settings;
session_start();
setlocale(LC_ALL, 'de_DE');
error_reporting(E_ALL);
define("ROOT", $_SERVER['DOCUMENT_ROOT']);
include(ROOT . '/system/config.php');
class CRM {
function getData($fetch) { //Daten einer fetchabfrage lesen
$clientOptions = include( 'config.php' ); //Daten der CRM Verbindung
$clientSettings = new Settings($clientOptions);
$client = new Client($clientSettings);
$metadata = MetadataCollection::instance($client);
$crmdata = $client->retrieveMultiple($fetch);
$data = null;
$i = 0;
foreach ($crmdata->Entities as $val) {
$data[$i] = $val;
$i++;
}
return $data;
}
}
//vars for the test
$systemuserVar = 'someone@doamin.com';
$salesorderID = 'b12447aa-9d93-e711-80e3-3863bb34b7d0';
$clientOptions = include(ROOT . '/system/config.php');
$clientSettings = new Settings($clientOptions);
$client = new Client($clientSettings);
$metadata = MetadataCollection::instance($client);
$searchOwner = '<fetch mapping="logical" version="1.0">'
. '<entity name="systemuser">'
. '<all-attributes /> '
. '<filter> '
. '<condition attribute="internalemailaddress" operator="eq" value="'.$systemuserVar.'" />'
. '</filter> '
. '</entity>'
. '</fetch>';
$oCRM = new CRM();
$systemuser = $oCRM->getData($searchOwner); //retrun object array
$salesorder = $client->entity('salesorder', $salesorderID);
$activityparty = $client->entity('activityparty');
$activityparty->partyid = new EntityReference('systemuser', $systemuser[0]);
$appointment = $client->entity('appointment');
$appointment->subject = 'test appointment';
$appointment->ownerid = $systemuser[0];
$appointment->regardingobjectid = $salesorder;
$appointment->description = 'description text';
$appointment->statuscode = 1;
$appointment->statecode = 0;
$appointment->scheduledstart = strtotime('24.01.2019 10:00');
$appointment->scheduledend = strtotime('24.01.2019 12:00');
$appointment->organizer = [ $activityparty ];
$appointment->requiredattendees = [ $activityparty ];
$appointmentID = $appointment->create();
I hope it helps
Wirbelrind
Hi @Wirbelrind
$systemuser[0]
is an entity, I don't believe it can be used everywhere where id is expected. It works for ownerid because we handle assignment of an entity to a lookup field. In other places where guid is required, it may not work. Basically instead of
$activityparty->partyid = new EntityReference('systemuser', $systemuser[0]);
try
$activityparty->partyid = new EntityReference('systemuser', $systemuser[0]->id);
Cheers George
Did this ever work? I think I've tried every combination above and still nothing.
@RichPitul activityparties is a, uhm, challenge. Can you share the code what you're trying to achieve and the error you're getting?
Hi @georged I am trying to do exactly this, create appointments and include a requiredattendee; which is a contact that is either already in CRM or a new Contact I've tried all combinations of the above code; string guids of the contact , entity references, anything I can think of. Strangely I don't receive an error message; the appointment get's created, just without the attendee added.
` function createAppointment($userId, $contactId, $start, $end, $subject, $description, $location, $contactEmail) { $contactActivityParty = $this->service->entity('activityparty'); $contactActivityParty->partyid = new EntityReference('systemuser', $systemuser[0]->id); $requiredAttendiesList = array(); $requiredAttendiesList[] = $contactActivityParty;
$appointment = $this->service->entity('appointment');
$appointment->subject = $subject;
$appointment->description = $description;
$appointment->location = $location;
$appointment->ownerid = $userId;
$appointment->scheduledstart = strtotime($start);
$appointment->scheduledend = strtotime($end);
$appointment->requiredattendees = $requiredAttendiesList;
$appointmentId = $appointment->create();
} `
@wizardist do we support activityparty
in the above context?
No, we do not.
This code implies deep insert and other forms of wizardry which are not supported. There is a plan to add support for easy activityparty handling in the Web API toolkit though so that a PHP equivalent of the code below is possible (see https://github.com/AlexaCRM/dynamics-webapi-toolkit/issues/16)
I'm trying to create a new appointment using the toolkit, but fail when setting the organizer or the required people.
Error messages:
where is my mistake or how can I fill the appropriate fields