locked
OR condition in link entity(Fetch XML) RRS feed

  • Question

  • We have a requirement in our project, the requirement is we have a common drop down field in contact and lead entity. we need to get records from appointments entity(using fetch xml) where as regarding object is either contact or lead but the condition is the common field value should be equal to 1 means one of the option value and the owner of appointments is either from  user1(one of user) or user2(one of user), Could any one suggest me to achieve this requirement. 

    Can any one suggest me to make bellow query as single 

    <!-- lead -->
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="appointment">
        <attribute name="activityid" />
    <attribute name="ownerid" />
        <filter type="and">
          <condition attribute="createdon" operator="this-week" />
          <filter type="or">
           <condition attribute="ownerid" operator="eq" uiname="user1" uitype="systemuser" value="{guid}" />
            <condition attribute="ownerid" operator="eq" uiname="user2" uitype="systemuser" value="{guid}" />
          </filter>
        </filter>
        <link-entity name="lead" from="leadid" to="regardingobjectid" alias="le">
          <filter type="and">
            <condition attribute="new_brand" operator="eq" value="1" />
          </filter>
        </link-entity>
      </entity>
    </fetch>
    <!-- contact -->
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="appointment">
        <attribute name="activityid" />
    <attribute name="ownerid" />
        <filter type="and">
          <condition attribute="createdon" operator="this-week" />
          <filter type="or">
            <condition attribute="ownerid" operator="eq" uiname="user1" uitype="systemuser" value="{guid}" />
            <condition attribute="ownerid" operator="eq" uiname="user2" uitype="systemuser" value="{guid}" />
          </filter>
        </filter>
        <link-entity name="contact" from="contactid" to="regardingobjectid" alias="co">
          <filter type="and">
            <condition attribute="new_brand" operator="eq" value="5" />
          </filter>
        </link-entity>
      </entity>
    </fetch>

    Tuesday, September 8, 2015 9:41 AM

All replies

  • Not sure I fully understand your requirement, but FetchXml only supports an OR condition across attributes in the same entity - you cannot use an OR condition across attributes from different entities. And no other workarounds (e.g. UNION queries) are possible either

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, September 10, 2015 9:26 AM
    Moderator
  • <fetch mapping="logical" version="1.0">
      <entity name="Appointment">
        <all-attributes />
        <filter type="or">
          <condition attribute="regardingobjecttypecode" operator="eq" value="2" />
          <condition attribute="regardingobjecttypecode" operator="eq" value="4" />
        </filter>
      </entity>
    </fetch>

    I wrote the SQL statement and then used the converter for fetch out at http://sql2fetchxml.com/ to push it to fetchXML. 

    Thursday, September 10, 2015 3:55 PM
  • I have to apply a condition for dropdown field which is common in lead and contact. 
    Wednesday, September 23, 2015 10:38 AM