You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用带IN运算符的嵌套FetchXML获取未归属解决方案的模型驱动应用

问题分析与解决方案

错误原因

你之前的写法错误在于:FetchXML的not-in运算符不支持直接嵌套子查询(即<fetch>标签作为条件值),它仅能接受明确的<value>值列表。系统会把你嵌套的XML内容当成Guid字符串解析,因此抛出“Guid格式不识别”的错误。

正确实现方式

要实现你SQL中的嵌套查询逻辑,应该使用FetchXML支持的not-exists运算符,它对应SQL中的NOT EXISTS子句,能完美实现“排除存在特定条件记录”的需求。

以下是与你SQL逻辑完全匹配的FetchXML:

<fetch distinct="true">
  <entity name="solutioncomponent">
    <attribute name="objectid" />
    <link-entity name="appmodule" from="appmoduleid" to="objectid" link-type="inner" alias="app">
      <attribute name="appmoduleid" />
      <attribute name="name" /> <!-- 可选,获取应用名称方便识别 -->
    </link-entity>
    <filter>
      <condition attribute="componenttype" operator="eq" value="80" />
    </filter>
    <!-- 核心逻辑:排除存在其他解决方案关联的应用 -->
    <filter type="not-exists">
      <condition attribute="objectid">
        <fetch>
          <entity name="solutioncomponent">
            <filter>
              <condition attribute="objectid" operator="eq" value="@solutioncomponent.objectid" />
              <condition attribute="componenttype" operator="eq" value="80" />
              <condition attribute="solutionid" operator="not-eq" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
              <condition attribute="solutionid" operator="not-eq" value="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" />
            </filter>
          </entity>
        </fetch>
      </condition>
    </filter>
  </entity>
</fetch>

补充:如果你需要的是「完全未归属任何解决方案」的应用

如果你的真实需求是获取没有关联任何解决方案的模型驱动应用(而非仅排除特定两个方案),可以用左连接+空值过滤的写法:

<fetch distinct="true">
  <entity name="appmodule">
    <attribute name="appmoduleid" />
    <attribute name="name" />
    <link-entity name="solutioncomponent" from="objectid" to="appmoduleid" link-type="outer" alias="sc">
      <filter>
        <condition attribute="componenttype" operator="eq" value="80" />
      </filter>
    </link-entity>
    <filter>
      <condition attribute="solutioncomponentid" operator="null" entityname="sc" />
    </filter>
  </entity>
</fetch>

内容的提问来源于stack exchange,提问作者redleo85

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 16:52:49