Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

(0) ShareShare
ReportReport
Posted on by 170

Hi,

I need to write a FetchXML for implementing the below conditions from same entity

((Cond1 OR Cond2) AND (Cond3 OR cond4))

Please let me know if you have gone through such type of requirement and written a fetchXML.

Thanks.

*This post is locked for comments

  • MSCRM learner Profile Picture
    MSCRM learner 170 on at
    RE: how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

    Thanks Karthik for the answer.

    Thanks Emre for letting me know about the plugin. I will download and install it in my CRM.

  • Suggested answer
    MSCRM learner Profile Picture
    MSCRM learner 170 on at
    RE: how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

    Hi Himanshu,

    Thanks for suggesting the way of Download FetchXML. Onwards I will follow the same.

  • MSCRM learner Profile Picture
    MSCRM learner 170 on at
    RE: how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

    Hi Gopalan,

    Thanks for your quick reply. It worked.

  • Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

    Hi,
    Additional to Gopalan and Himanshu 's answers,
    You can use XrmToolbox 's Fetchxml Builder plugin or directly prepare your query in MS CRM advanced find and download your query as fetchxml.

  • Suggested answer
    RE: how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

    Hi MSCRM,

    Here is a sample FetchXML query. Guess this is what you are looking for:

    <fetch top="50" >

    <entity name="contact" >

    <filter type="and" >

    <filter type="or" >

    <condition attribute="firstname" operator="not-null" />
    <condition attribute="lastname" operator="not-null" />

    </filter>

    <filter type="or" >

    <condition attribute="emailaddress1" operator="not-null" />

    <condition attribute="telephone1" operator="not-null" />

    </filter>

    </filter>

    </entity>

    </fetch>

     

    Regards,

    Karthik

    Please mark as Verified, if you find this useful

  • Suggested answer
    RE: how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

    Hi,

    You can use following fetch XML to achieve this.

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

     <entity name="account">

       <attribute name="name" />

       <attribute name="primarycontactid" />

       <attribute name="telephone1" />

       <attribute name="accountid" />

       <order attribute="name" descending="false" />

       <filter type="and">

         <filter type="and">

           <filter type="or">

             <condition attribute="name" operator="like" value="%abc%" />

             <condition attribute="name" operator="like" value="%xyz%" />

           </filter>

           <filter type="or">

             <condition attribute="accountnumber" operator="like" value="%123%" />

             <condition attribute="accountnumber" operator="like" value="%456%" />

           </filter>

         </filter>

       </filter>

     </entity>

    </fetch>

    One more thing, You can also create Advanced Find for your query and Download Fetch XML from there.

    Mark this answer as Verified if it helps.

    Thanks,

    Himanshu Prajapati

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: how to write FetchXML query for ((Cond1 OR Cond2) AND (Cond3 OR cond4))

    Hi

    You can use similar to the following.

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="account">
        <attribute name="name" />
        <attribute name="primarycontactid" />
        <attribute name="telephone1" />
        <attribute name="customertypecode" />
        <attribute name="accountid" />
        <order attribute="name" descending="false" />
        <filter type="and">
          <filter type="or">
            <condition attribute="name" operator="like" value="Test1%" />
            <condition attribute="name" operator="like" value="Test2%" />
          </filter>
          <filter type="or">
            <condition attribute="address1_city" operator="eq" value="London" />
            <condition attribute="address1_city" operator="eq" value="Leeds" />
          </filter>
        </filter>
      </entity>
    </fetch>


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans