AlexaCRM for PHP: Creating Incident (Case) in Dynamics CRM using CRM toolkit
Views (1104)
I love Learning! That too researching for helping a community user, more interestingly when the technology is new to you like AlexaCRM toolkit for PHP to interact with Dynamics CRM. Awesome!
When I started investigating this Stack Overflow question - I noticed that not a lot of online resources were available. Also some online IDE like codepen to test the snippet is totally missing and causing more trouble.
Download: AlexaCRM - php-crm-toolkit
Key learning is the below prerequisites:
use AlexaCRM\CRMToolkit\Client as OrganizationService;use AlexaCRM\CRMToolkit\Settings;use AlexaCRM\CRMToolkit\Entity\EntityReference;Otherwise some errors like this will give you hard time. Fatal error: Uncaught Error: Class 'EntityReference' not foundI gave some hints & OP was able to come up with the working code: The complete code snippet is below:
<?php
/**
* Use init.php if you didn't install the package via Composer
*/
require_once 'vendor/autoload.php';
use AlexaCRM\CRMToolkit\Client as OrganizationService;
use AlexaCRM\CRMToolkit\Settings;
use AlexaCRM\CRMToolkit\Entity\EntityReference;
$options = [
'serverUrl' => '**************************',
'username' => '**********************',
'password' => '*****************',
'authMode' => 'OnlineFederation',
];
$serviceSettings = new Settings( $options );
$service = new OrganizationService( $serviceSettings );
$contact = $service->entity( 'contact' );
$contact->firstname = 'John';
$contact->lastname = 'Doe';
$contact->emailaddress1 = 'john.doe@example.com';
$guid = $contact->create();
$incident = $service->entity('incident');
//echo '<pre>';print_r($incident);echo '</pre>';
$incident->title = 'Test Created With Proxy';
$incident->description = 'This is a test incident';
$incident->customerid = new EntityReference( 'contact', $guid );
//$incident->ID = $guid;//contactid responsiblecontactid primarycontactid
$incidentId = $incident->create();
?>It may help someone. :)
This was originally posted here.

Like
Report
*This post is locked for comments