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

Invalid argument supplied for foreach() Line 103 in Entity.php

Open tanberg opened this issue 4 years ago • 20 comments

When trying to simply fetch a record, I am running into this error that occurs during the creation construction of the Entity on line 103. When I look at the Organization.svc, I can find the Entity ('Lead') type that I am looking for, but as far as a list of attributes, I see no values. Could this be an error on the part of whoever setup the server that this feature is not available to the web?

Thanks in advance.

tanberg avatar Oct 17 '19 12:10 tanberg

Hi @tanberg

how are you fetching the records? Can you paste your code? I'm not quite sure what is the problem.

Thanks George

georged avatar Oct 18 '19 04:10 georged

$LeadId = '08644B69-XXXX-XXXX-A965-005056BB3D77'; $options = [ 'serverUrl' => 'correctdomain', 'username' => 'domain\username', 'password' => 'password', 'authMode' => 'Federation', ]; $serviceSettings = new Settings( $options ); $service = new OrganizationService( $serviceSettings );

    // create a new contact
    $lead = $service->entity( 'Lead', $LeadId);

tanberg avatar Oct 18 '19 12:10 tanberg

Hi @tanberg

what's the value for $LeadId? Are you sure it's the valid record in Dynamics 365/CRM system? If yes then are you getting any values at all, e.g. name or subject?

Thanks George

georged avatar Oct 18 '19 18:10 georged

Even if I just do $service->entity('Lead') it blows up during the construction of the Entity class. I have also tried Contact. I know they exist as I have seen them in the system's front end and can view the items within them. I get no values, simply blows up when trying to get Attributes from that Lead type.

tanberg avatar Oct 18 '19 18:10 tanberg

What version of php do you have?

georged avatar Oct 18 '19 19:10 georged

PHP Version 7.2.4

tanberg avatar Oct 18 '19 19:10 tanberg

and the Dynamics 365/ CRM version?

georged avatar Oct 18 '19 19:10 georged

9

tanberg avatar Oct 18 '19 19:10 tanberg

Hmmm, it looks like attributes is not initialised correctly. Maybe there is something coming from the metadata that breaks our code. Can you capture the logs (you'd need to plug your own log provider)?

@wizardist, any ideas what's going on here?

georged avatar Oct 18 '19 19:10 georged

i will do my best to get a logger in place and post back as fast as I can.

tanberg avatar Oct 18 '19 19:10 tanberg

Unfortunately server log just gives me the same stack trace back to Entity 103

tanberg avatar Oct 18 '19 19:10 tanberg

Not the server log, toolkit log that you can initialise when creating an org service instance

$service = new OrganizationService( $serviceSettings, $cache, $logger )

georged avatar Oct 18 '19 20:10 georged

@tanberg I wonder if you have the right permissions on CRM, e.g. reading metadata... What is the role of the user you're using to connect?

georged avatar Oct 18 '19 20:10 georged

@tanberg you're using display name Lead, it should be logical name, i.e. lead. Try $lead = $service->entity( 'lead', $LeadId); (thanks @wizardist !)

georged avatar Oct 19 '19 06:10 georged

Account is set up as Administrator, changed to 'lead' and still having the same issues.

tanberg avatar Oct 21 '19 15:10 tanberg

We also have a ticket in with the CRM provider and he has this link to follow the issue as well.

tanberg avatar Oct 21 '19 16:10 tanberg

Any other ideas @georged ??

tanberg avatar Oct 22 '19 14:10 tanberg

@tanberg I'm out of ideas.

We need the logs or you need to step through in debug to see what's coming back in the metadata and why attributes are not properly initialized.

Thanks

georged avatar Oct 22 '19 17:10 georged

This was using the cli-whoami.php essentially. I'm guessing that we have permission issues going on here.

ERROR TYPE: E_EXCEPTION MESSAGE: Access is denied. SITE PAGE: http://vgminsurance.localhost/testmeta.php LOCATION: /var/www/vgminsurance.com/vendor/alexacrm/php-crm-toolkit/src/Client.php LINE NUMBER: 1159 USER AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 OPERATING SYSTEM: Windows BROWSER: Chrome 77.0.3865.120 MOBILE: No ROBOT: No IP ADDRESS: 172.18.0.1 ERROR TIME: October 22, 2019 1:51 pm

--------------------------------------------------------------------------- PHP STACK TRACE --------------------------------------------------------------------------- #0 /var/www/vgminsurance.com/vendor/alexacrm/php-crm-toolkit/src/Client.php(2011): AlexaCRM\CRMToolkit\Client->getSoapResponse('https://crmstag...', '#1 /var/www/vgminsurance.com/vendor/alexacrm/php-crm-toolkit/src/Client.php(1857): AlexaCRM\CRMToolkit\Client->attemptSoapResponse('organization', Object(Closure)) #2 /var/www/vgminsurance.com/testmeta.php(57): AlexaCRM\CRMToolkit\Client->executeAction('WhoAmI') #3 {main}

tanberg avatar Oct 22 '19 18:10 tanberg

@tanberg looks like it's a permission issue. Can you double-check what role does your user account have in Dynamics 365?

georged avatar Nov 01 '19 09:11 georged