如何通过javascript或api在dynamics crm中通过文本搜索从多个实体获取记录?

How to get records from multiple entities by text search in dynamics crm by javascript or api?

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

之前使用它

虽然不受支持,但似乎可以通过 API 访问相关性搜索:https://bguidinger.com/blog/relevance-search-api

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

<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>

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

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

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