首页 > 解决方案 > 如何通过javascript或api在动态crm中通过文本搜索从多个实体中获取记录?

问题描述

我想通过匹配文本从多个实体中检索记录。是否可以使用 fetchxml 或 web api?我想通过javascript使用它。

标签: dynamics-crm

解决方案


这当然可以使用 FetchXML 实现。具体来说,您想使用like运算符。例如,以下 Fetch Query 在联系人姓名和电子邮件中搜索给定值:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="contact">
    <attribute name="fullname" />
    <attribute name="contactid" />
    <filter type="and">
      <filter type="or">
        <condition attribute="fullname" operator="like" value="%[Insert Dynamic Value]%" />
        <condition attribute="emailaddress1" operator="like" value="%[Insert Dynamic Value]%" />
      </filter>
    </filter>
  </entity>
</fetch>

为您要搜索的每个表编写一个类似的提取查询。

是否可以将所有实体组合在一起,而不是使用 fetchXml 单独请求?
不,根据设计,FetchXML 不支持查询多个不相关的记录。尽管您可以在单个 fetch 表达式中查询相关记录,但您无法跨多个表强制执行 OR 条件。例如,您不能编写类似于以下 SQL 的 FetchXML 查询:

SELECT *
FROM contact
JOIN account on contact.accountid = account.accountid
WHERE contact.fullname like '%foo%'
OR account.name like '%foo%'

推荐阅读