php-crm-toolkit icon indicating copy to clipboard operation
php-crm-toolkit copied to clipboard

Unable set organizer in Appointment (EntityCollection)

Open Wirbelrind opened this issue 5 years ago • 10 comments

I'm trying to create a new appointment using the toolkit, but fail when setting the organizer or the required people.

Error messages:

  • No parse handling implemented for type EntityCollection used by field organizer
  • No parse handling implemented for type EntityCollection used by field
  • No parse handling implemented for type EntityCollection used by field optionalattendees
$clientOptions = include(ROOT . '/system/config.php');
$clientSettings = new Settings($clientOptions);
$client = new Client($clientSettings);
$metadata = MetadataCollection::instance($client);
	
$salesorder = $client->entity('salesorder', $salesorderid);
        
$appointment = $client->entity('appointment');
$appointment->subject = $subject; //Betreff
$appointment->ownerid = $systemuserid;
$appointment->regardingobjectid = $salesorder;
$appointment->description = $description;
$appointment->statuscode = 1;
$appointment->statecode = 0;
$appointment->scheduledstart = strtotime($startdatetime);
$appointment->scheduledend = strtotime($enddatetime);
   
$appointmentID = $appointment->create();
     
$appointment = $client->entity('appointment', $appointmentID );
$appointment->requiredattendees =  new EntityReference ('systemuser', $systemuserid);
$appointment->update();


where is my mistake or how can I fill the appropriate fields

Wirbelrind avatar Jan 24 '19 09:01 Wirbelrind

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

georged avatar Jan 24 '19 11:01 georged

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

Wirbelrind avatar Jan 24 '19 15:01 Wirbelrind

Hi @Wirbelrind

can you paste the full code creating the subscription please?

Thanks George

georged avatar Jan 24 '19 16:01 georged

@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 = '[email protected]';
$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

Wirbelrind avatar Jan 24 '19 20:01 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

georged avatar Jan 26 '19 07:01 georged

Did this ever work? I think I've tried every combination above and still nothing.

RichPitul avatar Jun 17 '20 18:06 RichPitul

@RichPitul activityparties is a, uhm, challenge. Can you share the code what you're trying to achieve and the error you're getting?

georged avatar Jun 19 '20 02:06 georged

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

} `

RichPitul avatar Jun 19 '20 14:06 RichPitul

@wizardist do we support activityparty in the above context?

georged avatar Jun 19 '20 14:06 georged

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)

image

wizardist avatar Jun 19 '20 15:06 wizardist