如何根据fetchXML中的实体查询不同属性的关键字?

How to query a keyword on different attributes based on entity in fetchXML?

我在数据库中有 2 个实体;约会和电子邮件。我想编写一个搜索函数来获取所有包含用户输入的字符串的约会和电子邮件。但是,我想根据它是哪个实体来搜索不同的属性。例如:我想获取所有具有包含字符串 "meeting today" 的属性 subject 的约会,我还想获取所有具有包含相同字符串的属性 description 的电子邮件。所以简单来说,只搜索约会的主题行,只搜索电子邮件的描述。

到目前为止,我的 fetchXml 是这样的:

<fetch count="10" distinct="true" mapping="logical" no-lock="true" output-format="xml-platform" page="1" returntotalrecordcount="false" version="1.0">
    <entity name="activitypointer">
        <attribute name="subject"/>
        <attribute name="description"/>
        <attribute name="activitytypecode"/>
        <filter type="or">
            <condition attribute="activitytypecode" operator="like">
                <value>Email</value>
            </condition>
            <filter type="and">
                <condition attribute="description" operator="like" value="%meeting today%"/>
            </filter>
        </filter>
        <filter type="or">
            <condition attribute="activitytypecode" operator="like">
                <value>Appointment</value>
            </condition>
            <filter type="and">
                <condition attribute="subject" operator="like" value="%meeting today%"/>
            </filter>
        </filter>
    </entity>
</fetch>

不过这似乎并没有取回任何记录。在查询单个实体类型时,我可以成功获取记录,但是放置两个过滤器不会 return 任何东西。我要问的是可以在 fetchXML 中做什么吗?还是我构建查询的方式有问题?

我刚刚在我的环境中做了一个快速测试,这是有效的。您可以在 XrmToolBox FetchXml 构建器 editing/testing 之前的高级查找和下载 fetchxml 中构建此类查询。

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" >
  <entity name="activitypointer" >
    <attribute name="activitytypecode" />
    <attribute name="subject" />
    <filter type="and" >
      <filter type="or" >
        <filter type="and" >
          <condition attribute="activitytypecode" operator="eq" value="4202" />
          <condition attribute="subject" operator="like" value="%test%" />
        </filter>
        <filter type="and" >
          <condition attribute="activitytypecode" operator="eq" value="4201" />
          <condition attribute="description" operator="like" value="%test%" />
        </filter>
      </filter>
    </filter>
  </entity>
</fetch>