简体   繁体   中英

How To Create a case Or Incident In Microsoft Dynamics Online CRM using php-crm-toolkit

I am trying to create case it's giving me

"Fatal error: Uncaught AlexaCRM\\CRMToolkit\\SoapFault: You should specify a parent contact or account. in D:\\wamp64\\www\\php_crm\\vendor\\alexacrm\\php-crm-toolkit\\src\\Client.php on line 1159"

My code:

<?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;



$options = [
    'serverUrl' => '**********************',
    'username' => '****************',
    'password' => '*************',
    'authMode' => '***********************',
];

$serviceSettings = new Settings( $options );
$service = new OrganizationService( $serviceSettings );


// create a new contact
$incident = $service->entity( 'incident' );
$incident->title = 'Test Created With Proxy';
$incident->description = 'This is a test incident';
$incidentId = $incident->create();

?>

Finally I created case by using following code:

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

The error is very clear, you must mention the customer of the incident - Parent account or contact. Check the below code, it should work (not sure about php syntax).

$incident = $service->entity( 'incident' );
$incident->title = 'Test Created With Proxy';
$incident->description = 'This is a test incident';
$incident->customerid = new EntityReference( 'contact', 'GUID HERE' );
$incidentId = $incident->create();

Reference

From the above link, adding another snippet for lookup field assignment:

$customer = $client->entity( 'contact' );
$customer->ID = 'GUID HERE';
$incident-> customerid = $customer;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM