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



我在数据库中有2个实体;一个约会和一个电子邮件。我想编写一个搜索函数,用于获取包含用户输入的字符串的所有约会和电子邮件。但是,我想根据实体搜索不同的属性。例如:我想获取属性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>

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

我刚刚在我的环境中做了一个快速测试,这很有效。您可以在高级查找和下载fetchxml中构建此类查询,然后在XrmToolBox 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>

最新更新