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

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

Open
tanberg opened this issue Oct 17, 2019 · 20 comments
Open

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

tanberg opened this issue Oct 17, 2019 · 20 comments

Comments

@tanberg
Copy link

tanberg commented Oct 17, 2019

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.

@georged
Copy link
Contributor

georged commented Oct 18, 2019

Hi @tanberg

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

Thanks
George

@tanberg
Copy link
Author

tanberg commented Oct 18, 2019

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

@georged
Copy link
Contributor

georged commented Oct 18, 2019

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

@tanberg
Copy link
Author

tanberg commented Oct 18, 2019

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.

@georged
Copy link
Contributor

georged commented Oct 18, 2019

What version of php do you have?

@tanberg
Copy link
Author

tanberg commented Oct 18, 2019

PHP Version 7.2.4

@georged
Copy link
Contributor

georged commented Oct 18, 2019

and the Dynamics 365/ CRM version?

@tanberg
Copy link
Author

tanberg commented Oct 18, 2019

9

@georged
Copy link
Contributor

georged commented Oct 18, 2019

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?

@tanberg
Copy link
Author

tanberg commented Oct 18, 2019

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

@tanberg
Copy link
Author

tanberg commented Oct 18, 2019

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

@georged
Copy link
Contributor

georged commented Oct 18, 2019

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

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

@georged
Copy link
Contributor

georged commented Oct 18, 2019

@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
Copy link
Contributor

georged commented Oct 19, 2019

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

@tanberg
Copy link
Author

tanberg commented Oct 21, 2019

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

@tanberg
Copy link
Author

tanberg commented Oct 21, 2019

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

@tanberg
Copy link
Author

tanberg commented Oct 22, 2019

Any other ideas @georged ??

@georged
Copy link
Contributor

georged commented Oct 22, 2019

@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

@tanberg
Copy link
Author

tanberg commented Oct 22, 2019

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}

@georged
Copy link
Contributor

georged commented Nov 1, 2019

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

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

2 participants