FetchXML Tutotorial

FetchXML OR Condition in Dynamic CRM

In this article, we will learn FetchXML OR Condition in Dynamic CRM.

In this blog, we will learn how to use FetchXML OR Condition in Dynamic CRM.
FetchXML OR Condition in Dynamic CRM
The OR operators are used to filter records based on more than one condition:

The OR operator displays a record if any of the conditions separated by OR is TRUE.
Syntax :

<fetch mapping="logical" version="1.0">
  <entity name="entityname">
    <all-attributes />
    <filter type="or">
      <condition attribute="attribute_name" operator="" value="" />
      <condition attribute="attribute_name" operator="" value="" />
    </filter>
  </entity>
</fetch>

Customer Entity Database Record:
fetchxml-or-condition-dynamic-crm

The following fetchxml statement selects all fields from “Customers” where city is “Buxar” OR “Varanasi”:

OR Example :
Key Point:
vnks_customer:It is a logical name of entity.
vnks_country,vnks_city:It is a logical name of attribute/field.
vnks_address:It is a logical name of attribute/field.
vnks_postalcode: It is a logical name of attribute/field.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" >
    <entity name="vnks_customer" >
        <attribute name="vnks_name" />
        <attribute name="vnks_address" />
        <attribute name="vnks_city" />
        <attribute name="vnks_postalcode" />
        <attribute name="vnks_country" />
        <filter type="or" >
            <condition attribute="vnks_city" operator="eq" value="Buxar" />
            <condition attribute="vnks_city" operator="eq" value="Varanasi" />
        </filter>
    </entity>
</fetch>

Result:

 <result>
        <vnks_name>
            Kishan Yadav
        </vnks_name>
        <vnks_address>
            Varansai
        </vnks_address>
        <vnks_city>
            Varanasi
        </vnks_city>
        <vnks_postalcode>
            23457
        </vnks_postalcode>
        <vnks_country>
            India
        </vnks_country>
        <vnks_customerid>
            {DEBBC9B8-2640-EA11-A812-000D3AF02D13}
        </vnks_customerid>
    </result>
    <result>
        <vnks_name>
            Karuna
        </vnks_name>
        <vnks_address>
            Buxar
        </vnks_address>
        <vnks_city>
            Buxar
        </vnks_city>
        <vnks_postalcode>
            897645
        </vnks_postalcode>
        <vnks_country>
            India
        </vnks_country>
        <vnks_customerid>
            {0AF7F5CE-2640-EA11-A812-000D3AF02D13}
        </vnks_customerid>
    </result>
    <result>
        <vnks_name>
            Karuna
        </vnks_name>
        <vnks_address>
            Buxar
        </vnks_address>
        <vnks_city>
            Buxar
        </vnks_city>
        <vnks_postalcode>
            908767
        </vnks_postalcode>
        <vnks_country>
            India
        </vnks_country>
        <vnks_customerid>
            {D1EFDAE7-2640-EA11-A812-000D3AF02D13}
        </vnks_customerid>
    </result>
    <result>
        <vnks_name>
            Ravi
        </vnks_name>
        <vnks_address>
            Varanasi
        </vnks_address>
        <vnks_city>
            Varanasi
        </vnks_city>
        <vnks_postalcode>
            987689
        </vnks_postalcode>
        <vnks_country>
            US
        </vnks_country>
        <vnks_customerid>
            {CB0C7FFC-2640-EA11-A812-000D3AF02D13}
        </vnks_customerid>
    </result

Any question and suggestion related to this topic FetchXML OR Condition in Dynamic CRM please comment. Thank you

Leave a Reply

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