Guy E
Guy E

Reputation: 1927

Use condition to get only records with non-numbers values in a fetchXml Dynamics CRM query

I'm querying Dynamics CRM using fetchXML. I have an entity that have attribute (placeName) where its value is either string or value of a number. I would like to have condition that only the records with a non-number value should be selected. I didn't find any solution for that in the dynamics documents, but maybe there is a solution using an "out-of-the-box" (custom condition). This is my current fetch query:

<fetch mapping="logical" distinct="true" version="1.0">
  <entity name="locations">
    <attribute name="placeID" />
    <attribute name="placeName" /> // This can be values like "home" or 100 - I would like to take out only those which are not a number
  </entity>

Upvotes: 2

Views: 1425

Answers (1)

OfirD
OfirD

Reputation: 10490

Though I couldn't find it documented anywhere, you can use like operator with regex-ish syntax.

For example, the following query would retrieve systemuser records that only contains numbers in their domainname:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
   <entity name="systemuser">
      <condition attribute="domainname" operator="like" value="%[0-9]%" />
   </entity>
</fetch>

And in your case, the following would retrieve records only with letters a-z or A-Z:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
   <entity name="locations">
      <condition attribute="placeName" operator="not-like" value="%[0-9]%" />
   </entity>
</fetch>

Upvotes: 3

Related Questions