Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable set organizer in Appointment (EntityCollection) #73

Open
Wirbelrind opened this issue Jan 24, 2019 · 10 comments
Open

Unable set organizer in Appointment (EntityCollection) #73

Wirbelrind opened this issue Jan 24, 2019 · 10 comments

Comments

@Wirbelrind
Copy link

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

@georged
Copy link
Contributor

georged commented Jan 24, 2019

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

@Wirbelrind
Copy link
Author

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

@georged
Copy link
Contributor

georged commented Jan 24, 2019

Hi @Wirbelrind

can you paste the full code creating the subscription please?

Thanks
George

@Wirbelrind
Copy link
Author

Wirbelrind commented Jan 24, 2019

@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

@georged
Copy link
Contributor

georged commented Jan 26, 2019

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

@RichPitul
Copy link

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

@georged
Copy link
Contributor

georged commented Jun 19, 2020

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

@RichPitul
Copy link

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

}
`

@georged
Copy link
Contributor

georged commented Jun 19, 2020

@wizardist do we support activityparty in the above context?

@wizardist
Copy link
Collaborator

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 AlexaCRM/dynamics-webapi-toolkit#16)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants