AlexaCRM / dynamics-webapi-toolkit

Dynamics 365 Web API Toolkit for PHP
MIT License
77 stars 58 forks source link

Allow empty baseType in MetaData #63

Closed attrib closed 3 years ago

attrib commented 3 years ago

I have a case where a entity type doesn't have any base type.

This results in an error as the parameter from rebuildFromBase is not nullable.

This PR fixes this issue.

georged commented 3 years ago

Hey @attrib, thanks for the PR. Can you send a sample of an entity type that does not have a base type? I do not recall ever coming across of that in Dataverse

attrib commented 3 years ago

Its very strange, it seems like its all of them for this instance. We connect to multiple dynamic instances from different customers and this is the only one where there is no base type in the metadata.

After I asked now the problem could be that they have a self hosted Dynamics Nav instance and not a online dynamics 365 instance, but despite this base type issue this library seems to do the job. I can't test writing at the moment as the API user we have, doesn't have write access at the moment

attrib commented 3 years ago

Here a part of the metadata (I removed some fields and renamed the type)

      <EntityType Name="XXXContactList">
        <Key>
          <PropertyRef Name="No" />
        </Key>
        <Property Name="No" Type="Edm.String" Nullable="false">
          <Annotation Term="NAV.LabelId" String="No" />
          <Annotation Term="NAV.NavType">
            <EnumMember>NAV.NavType/String</EnumMember>
          </Annotation>
          <Annotation Term="NAV.IsRequired" Bool="true" />
        </Property>
        <Property Name="Exclude_from_Segment" Type="Edm.Boolean">
          <Annotation Term="NAV.LabelId" String="Exclude_from_Segment" />
          <Annotation Term="NAV.NavType">
            <EnumMember>NAV.NavType/Bool</EnumMember>
          </Annotation>
        </Property>
        <Property Name="Name" Type="Edm.String">
          <Annotation Term="NAV.LabelId" String="Name" />
          <Annotation Term="NAV.NavType">
            <EnumMember>NAV.NavType/String</EnumMember>
          </Annotation>
        </Property>
        <Property Name="Company_Name" Type="Edm.String">
          <Annotation Term="NAV.LabelId" String="Company_Name" />
          <Annotation Term="NAV.NavType">
            <EnumMember>NAV.NavType/String</EnumMember>
          </Annotation>
        </Property>
...
        <NavigationProperty Name="Company_Name_Link" Type="Collection(NAV.XXXContactList)" />
        <Annotation Term="NAV.LabelId" String="XXXContactList" />
        <Annotation Term="NAV.IsReadOnly" Bool="true" />
      </EntityType>
georged commented 3 years ago

After I asked now the problem could be that they have a self hosted Dynamics Nav instance and not a online dynamics 365 instance, but despite this base type issue this library seems to do the job.

Wait a minute. NAV?! This toolkit is for Dataverse (aka CDS aka Dynamics 365 CRM aka Dynamics CRM). We never planned nor tested functionality with anything else. Are you saying it's actually working with NAV? I'd be very surprised if it did.

attrib commented 3 years ago

From what I could test till now, it does work with NAV. Like said before I'm currently waiting for more permissions to also test write/update.

NAV supports OData and at the end you only use OData methods, so I'm not that suprised that it does work :) As far as I understood NAV was the predecessor of Dataverse.

To get it working with NAV only change I did was this commit and a own Client (extended AlexaCRM\WebAPI\OData\Client) that supports NTLM. (For reference https://gist.github.com/attrib/f34def7ff888d96a05c7a9410ee8f453 )

georged commented 3 years ago

@attrib I've merged the commit as it has no impact on the existing working scenarios. Glad it's working with NAV - I must say I'm pleasantly surprised /cc @wizardist

attrib commented 3 years ago

Big thanks for the quick response!

Do you want me to keep you posted, about my findings with NAV, as soon as I can test other actions? (Still waiting of response to get more privilages from customer)

georged commented 3 years ago

NAV sounds like an interesting exercise. Just keep the changes in the fork and we'll see what happens. Unfortunately, we have limited NAV knowledge to assist.