web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    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>


  • Suggested answer
    Community Member Profile Picture
    on at

    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

  • Suggested answer
    KARTHIKGOWTHAM@SUYATITECH Profile Picture
    175 on at

    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

  • Emre GULCAN Profile Picture
    2,379 on at

    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.

  • MSCRM learner Profile Picture
    170 on at

    Hi Gopalan,

    Thanks for your quick reply. It worked.

  • Suggested answer
    MSCRM learner Profile Picture
    170 on at

    Hi Himanshu,

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

  • MSCRM learner Profile Picture
    170 on at

    Thanks Karthik for the answer.

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans