How to request Dynamics CRM web API using custom FetchXml using quantity value filter?

I am trying to fetch XML using WEB API / api / data / v8.x. Everything is fine if I have a query that includes "where the attribute contains a numeric value." For example, the following fetchXML file to search for an account with a phone number contains β€œ03”:

<fetch mapping="logical"> <entity name="account"> <attribute name="name" /> <attribute name="telephone1" /> <order attribute="name" descending="false" /> <filter type="and"> <condition attribute="telephone1" operator="like" value="%03%" /> </filter> </entity> </fetch> 

When we run it through the GET on the WEB API:

 https://CRM_URL/api/data/v8.0/accounts?fetchXml=<fetch%20mapping%3D"logical"><entity%20name%3D"account"><attribute%20name%3D"name"%20%2F><attribute%20name%3D"telephone1"%20%2F><order%20attribute%3D"name"%20descending%3D"false"%20%2F><filter%20type%3D"and"><condition%20attribute%3D"telephone1"%20operator%3D"like"%20value%3D"%2503%25"%20%2F><%2Ffilter><%2Fentity><%2Ffetch> 

The CRM Web API returns an invalid XML error as follows:

{"error": {"code": "," message ":" Invalid XML. "," internalerror ": {" message ":" Invalid XML. "," type ":" System.ServiceModel.FaultException`1 [[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version = 8.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35]] "}}}

The query is executed normally if the filter value does not start with a number or I delete "%" in the filter value. My conclusion is that this is due to the encoding and decoding of "% + number" in my filter value.

Is there something wrong with my request or is it a Dynamics CRM API error? any work around?

+5
source share
2 answers

Here, Dynamics 365 internally decodes the FetchXML query string twice. This was reported to the development team. They will provide a fix for the upcoming release, and possibly the latest public release. Prior to this, you can try to double-encode the query string or replace all occurrences of the % character with %25 after encoding. For example, the string value%3D"%2503%25" can be replaced with value%3D"%252503%2525" . Please note that after the fix is ​​available, the workaround will no longer work.

+3
source

I don't know why this does not work, but you can use a filter to get a phone number containing number 3.

 cc_WebAPI_ServiceURI/accounts?$filter=contains(telephone1,'3') 
0
source

Source: https://habr.com/ru/post/1260553/


All Articles