How to send a lead with a lookup field to dynamics CRM (using PHP and AlexaCRM toolkit)?

198 views Asked by At

I'm using AlexaCRM and I tried sending a lead with a lookup field. I don't have any problems with other fields. This is my code:

use AlexaCRM\CRMToolkit\Client as OrganizationService;
use AlexaCRM\CRMToolkit\Settings;
use AlexaCRM\CRMToolkit\Entity\EntityReference;

try {

$options = [
    'serverUrl' => 'urldelcrm',
    'username' => 'user',
    'password' => 'pass',
    'authMode' => 'OnlineFederation',
];

$serviceSettings = new Settings( $options );
$service = new OrganizationService( $serviceSettings);
$lead = $service->entity('lead');
$lead->firstname = $data['fields']['name'];

//...Lookup field:
$guid = "1111111-1111-111-11-11" // guid campaign
$lead->campaignid = new EntityReference('campaign', $guid );
$leadId = $lead->create();

} catch (\Exception $e) {
   // echo $e->getMessage();
}

But when I peek in the CRM the field, "campaignid" is empty. Then I printed the $lead variable and the "campaignid" is empty too. Also I tried,

$lead->campaignid = $service->entity( 'campaign', $guid );

Instead of EntityReference('campaign', $guid).

What is wrong here?

0

There are 0 answers