rappen / FetchXMLBuilder

FetchXML Builder for XrmToolBox and Microsoft Dynamics 365 / CRM
https://fetchxmlbuilder.com/
GNU General Public License v3.0
133 stars 55 forks source link

Fetch Error: Incorrect Data Type Expected #1014

Open ryncdr opened 5 months ago

ryncdr commented 5 months ago

Filtering the audit table with ObjectTypeCode is incorrectly expecting an integer rather than string. See Microsoft: Web API Reference for entity definition.

The OData calls successfully using the same parameters which are failing in FetchXMLBuilder: https://redacted.dynamics.com/api/data/v9.2/audits?$filter=(Microsoft.Dynamics.CRM.LastXHours(PropertyName='createdon',PropertyValue=1) and objecttypecode ne 'systemuser')&$top=50


System.ServiceModel.FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>:
An exception System.FormatException was thrown while trying to convert input value '[REDACTED]' to attribute 'audit.objecttypecode'. Expected type of attribute value: System.Int32. Exception raised: Input string was not in a correct format.
FetchXML Builder

Server stack trace: 
- System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
- System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
- System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
- System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
- Microsoft.Xrm.Tooling.Connector.CrmServiceClient.RetrieveMultiple(QueryBase query)
- Rappen.XTB.FetchXmlBuilder.FetchXmlBuilder.RetrieveMultiple(QueryBase query, Boolean allrecords)
- Rappen.XTB.FetchXmlBuilder.FetchXmlBuilder.<>c__DisplayClass125_0.<RetrieveMultiple>b__0(BackgroundWorker worker, DoWorkEventArgs eventargs)
- System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
- System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

<fetch top="50">
  <entity name="audit">
    <filter type="and">
      <condition attribute="createdon" operator="last-x-hours" value="1" />
      <condition attribute="objecttypecode" operator="ne" value="systemuser" />
    </filter>
  </entity>
</fetch>

rappen commented 5 months ago

The ObjectTypeCode columns are often fishy... I'll try to find a good/better solution to this and similar issue.