rappen / FetchXMLBuilder

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

Contains is not supported in FetchXml #708

Closed rappen closed 2 years ago

rappen commented 2 years ago

Error of Contains operator, here with a super simple query (see in the end).

Related to #706

This docs says it should work, but give a SQL error, but this one gets a Fetch XML error, just "Unknown Condition Operator: contains".

Tried some code to convert from QueryExpression to FetchXml. Code:

var query = new QueryExpression("kbarticle");
query.ColumnSet.AddColumns("title");
query.Criteria.AddCondition("content", ConditionOperator.Contains, "A");
var fetch = (Service.Execute(new QueryExpressionToFetchXmlRequest { Query = query }) as QueryExpressionToFetchXmlResponse).FetchXml;

I get a bit more info - it fails with exception "Unknown Condition Operator: Contains. FetchXml does not support it".

Which seems to mean that some features work in QX, but not in Fetch. I know the reverse, but not this! Are there more features supported in QX but not in Fetch? Is this documented? I am just a bad Binging person... Has @JimDaly any more info/link?


Error message from FetchXML Builder below:


System.ServiceModel.FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>:
Unknown Condition Operator: contains
mscorlib

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)
- Cinteros.Xrm.FetchXmlBuilder.FetchXmlBuilder.<>c__DisplayClass112_0.<RetrieveMultiple>b__0(BackgroundWorker worker, DoWorkEventArgs eventargs)
- System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
- System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

<fetch>
  <entity name="account">
    <attribute name="name" />
    <filter>
      <condition attribute="name" operator="contains" value="A" />
    </filter>
  </entity>
</fetch>

JimDaly commented 2 years ago

@rappen Looking at the FetchXml Schema I don't see a definition for CONTAINS. We can see it is in the ConditionOperator used by QueryExpression. I expected to find it in the FetchXml Schema, but it isn't there.

rappen commented 2 years ago

Right. So where is the bug...? In me or MS? 😉

A bit funny that I can find contain-values and not-contain-values, but not the simpler like contains...

A few years back, I got clear fact that MS is not anymore updating the FetchXml Schema that I used to use in this tool as a "fact" for the code. This is why I can not use that anymore... (I did earlier find it in the SDK we had downloaded)

JimDaly commented 2 years ago

contains-values and not-contains-values are relatively new to support multi-select optionsets. Contains has been around a long time and is pretty much only used for certain KB articles attributes that have special indexing. The error message is pretty clear, but I don't see it documented anywhere.