FetchXML Tutotorial, Uncategorized

How to pass null and not null operator in FetchXML

In this blog we will learn How to pass null and not null operator in FetchXML?

First learn about What is a NULL Value?

A field with a NULL value is a field with no value.
If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value.

Note: Always remember this point, A NULL value is different from a zero value or a field that contains spaces.

How to use null operator in FetchXML ?
The following FetchXML lists all customers with a NULL value in the “Address” field:

<fetch mapping="logical" version="1.0">
  <entity name="customers">
    <attribute name="customername" />
    <attribute name="contactname" />
    <attribute name="address" />
    <filter>
      <condition attribute="address" operator="null" />
    </filter>
  </entity>
</fetch>

Pass not-null operator in FetchXML

The NOT-NULL operator is used to test for non-empty values (NOT NULL values).

The following FetchXML lists all customers with a value in the “Address” field:

<fetch mapping="logical" version="1.0">
  <entity name="customers">
    <attribute name="customername" />
    <attribute name="contactname" />
    <attribute name="address" />
    <filter>
      <condition attribute="address" operator="not-null" />
    </filter>
  </entity>
</fetch>

Leave a Reply

Your email address will not be published. Required fields are marked *