Xrm.Tools.CRMWebAPI icon indicating copy to clipboard operation
Xrm.Tools.CRMWebAPI copied to clipboard

Problem with ampersand in FetchXML in GetList()

Open msymer opened this issue 5 years ago • 2 comments

When you want to search for example for client by name "H&M" and you write this condition in FetchXML <condition attribute="name" operator="eq" value="H&M" /> , it does not work. I tried all the combinations with & %26 ... but none is working.

Solution can be this in CrmWebAPI.cs (line 1067):

if (firstParam)
        {
          fullurl = fullurl + string.Format("?fetchXml={0}", Uri.EscapeUriString(queryOptions.FetchXml).Replace("&", "%26amp%3B"));
        }
        else
        {
          fullurl = fullurl + string.Format("&fetchXml={0}", Uri.EscapeUriString(queryOptions.FetchXml).Replace("&", "%26amp%3B"));
        }
        firstParam = false;

msymer avatar Aug 21 '20 08:08 msymer

Bump, ran into the same issue. Going to have implement my own odata service for this one call...

WizardMatthew avatar Jul 16 '21 23:07 WizardMatthew

Not just that, but colon ( : ) doesn't work either... Which is bad, because you can't query on DateTime, if there is a time component in the query. So this doesn't work: <condition attribute="name" operator="lt" value="2022-09-09T08:00Z" />

Quick and (seems to be working) dirty fix is to use not just the FetchXml parameter for querying, but also the Filter one...

return new CRMGetListOptions { FetchXml = $@"<fetch top=""1""> ..., Filter = $"date_field le '2022-09-09T08:30Z'" };

Ugly but works. There are so much more problems with this library unfortunately...

For example, using this library with the XrmToolBox's Early Bound Generator for Crm Web Api, if you put a valid Guid value into a string field on a CRM entity, it will parse it automatically to a Guid type, which brokes the proxy classes' getter...

x4int avatar Sep 09 '22 09:09 x4int