代码之家  ›  专栏  ›  技术社区  ›  Damkulul

如何使用fetch进行过滤以获得准确的结果?

  •  0
  • Damkulul  · 技术社区  · 8 年前

    我需要获取所有有电话呼叫的帐户 state open ,所以我创建了一个关于fetch的查询,并得到了一些结果。

    在检查了我的结果后,我发现我得到的所有帐户中至少有一个尚未打开的电话呼叫,但我需要得到以下帐户: 全部的 他们连接的电话中有个未打开(不能有1个处于打开状态),是否可以通过提取来完成?

    **“未打开”是指取消或完成的状态。

    以下是我的获取查询:

    @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
      <entity name='account'>
        <attribute name='name' />                                        
        <order attribute='accountamount' descending='true' />
        <link-entity name='phonecall' from='regardingobjectid' to='accountid' alias='ab'>
          <filter type='and'>
            <condition attribute='statecode' operator='ne' value='0' />
          </filter>
        </link-entity>
      </entity>
    </fetch>";
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Arun Vinoth PrecogTechnologies    8 年前

    您要查找的是不匹配查询。这可以通过使用fetchxml进行2次查询来实现。

    第一次查询 :您必须提取所有打开电话呼叫的帐户。

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
      <entity name="account" >
        <attribute name="accountid" />
        <order attribute="accountamount" descending="true" />
        <link-entity name="phonecall" from="regardingobjectid" to="accountid" alias="ab" >
          <filter type="and" >
            <condition attribute="statecode" operator="eq" value="0" />
          </filter>
        </link-entity>
      </entity>
    </fetch>
    

    第二次查询 :迭代(&I);将第一个查询帐户结果集作为 <value> 如下图所示,过滤掉它们。

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
      <entity name="account" >
        <attribute name="name" />
        <attribute name="primarycontactid" />
        <attribute name="telephone1" />
        <attribute name="accountid" />
        <order attribute="name" descending="false" />
        <filter type="and" >
          <condition attribute="accountid" operator="not-in" >
            <value><GUID of ACCOUNT1 with OPEN PHONECALL></value>
            <value><GUID of ACCOUNT2 with OPEN PHONECALL></value>
            <value><GUID of ACCOUNT3 with OPEN PHONECALL></value>
          </condition>
        </filter>
      </entity>
    </fetch>
    

    Read for idea