【问题标题】:CRM web api expand along with filter - inner join or left join?CRM web api与过滤器一起扩展-内连接还是左连接?
【发布时间】:2020-12-13 15:02:14
【问题描述】:

我正在尝试使用 web api 查询并且没有 fetchxml,我能够构建此端点,但结果集的行为类似于 LEFT OUTER JOIN,但我需要 INNER JOIN。

new_demo 正在查找 new_currentappointment(最近的记录是从子网格列表中捕获的),new_currentappointment 正在查找 new_user

我想要new_demonew_currentappointment_lookup 的列表,其中new_user_lookup 是过滤器。

https://crmdev.crm.dynamics.com/api/data/v9.1/new_demo?$select=new_attribute_one&$expand=new_currentappointment_lookup($select=new_attribute_two;$filter=_new_user_lookup_value eq <guid>)

结果将每个new_demo 带入系统,但扩展过滤器仅产生空值。如何从主结果中的扩展实体中消除过滤后的空结果?

"value": [
    {
      "@odata.etag": "W/\"608177550\"",
      "new_attribute_one": "Demo 1",
    
      "new_currentappointment_lookup": {
        "new_attribute_two": "testing comments",
        "_new_user_lookup_value": "guid",
      },
    },
    {
      "@odata.etag": "W/\"608177790\"",
      "new_attribute_one": "Demo 2",
      
      "new_currentappointment_lookup": null,
    }
  ]

ASP.NET web api documentation 中解释的这个结果是我正在寻找的结果,但我找不到 Dynamics CRM web api 的结果。还有其他我想念的简单方法吗?

【问题讨论】:

标签: asp.net-web-api dynamics-crm dynamics-crm-webapi


【解决方案1】:

来自Doc feedback: CRM web api expand along with filter - inner join or left join?

这是与您的场景等效的查询:

{{webapiurl}}incidents?$select=title
&$expand=customerid_account($select=name;
$expand=primarycontactid($select=fullname;
$filter=contactid eq '384d0f84-7de6-ea11-a817-000d3a122b89'))

$filter 只控制记录是否展开。

这就是区别:

{
    "@odata.etag": "W/\"31762030\"",
    "title": "Sample Case",
    "incidentid": "d3d685f9-cddd-ea11-a813-000d3a122b89",
    "customerid_account": {
        "name": "Fourth Coffee",
        "accountid": "ccd685f9-cddd-ea11-a813-000d3a122b89",
        "primarycontactid": {
            "fullname": "Charlie Brown",
            "contactid": "384d0f84-7de6-ea11-a817-000d3a122b89"
        }
    }
}

还有这个:

{
    "@odata.etag": "W/\"31762030\"",
    "title": "Sample Case",
    "incidentid": "d3d685f9-cddd-ea11-a813-000d3a122b89",
    "customerid_account": {
        "name": "Fourth Coffee",
        "accountid": "ccd685f9-cddd-ea11-a813-000d3a122b89",
        "primarycontactid": null
    }
}

参见this example(Ctrl+F“展开中的嵌套过滤器”),其中返回所有人员,但仅展开与 $filter 匹配的行程。

所以扩展中的 $filter 行为只会控制是否返回细节。 这不是 INNER JOIN 行为。 您需要使用 FetchXml 来实现这一点。

【讨论】:

  • 是的,类似的结构。如果这也可以使用该模式进行测试,那么它的行为可能相同。你要我检查吗?
  • 谢谢,这澄清了它是预期的行为。而 FetchXml 是内连接的唯一方式。
【解决方案2】:

这在以前可能是不可能的,但现在可以通过针对导航属性添加顶级过滤器,通过 Web API 为关系更深一层获得 INNER JOIN 行为。对于您的示例,它看起来像这样:

https://crmdev.crm.dynamics.com/api/data/v9.1/new_demo?$select=new_attribute_one&amp;$filter=(new_currentappointment_lookup/_new_user_lookup_value eq &lt;guid&gt;)&amp;$expand=new_currentappointment_lookup($select=new_attribute_two)

XrmToolbox 中的 FetchXML Builder 工具是帮助创建 Web API 查询的好地方。在 fetch 中创建查询,然后在 View 菜单中启用 OData 4.0 选项,它将显示等效的 Web API 查询(如果可能的话)。

【讨论】:

  • 这需要更多的支持。我以为我将不得不重写我的 PCF 的一部分来使用 FecthXml,但这是天赐之物。
猜你喜欢
  • 1970-01-01
  • 2010-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
  • 2021-12-25
相关资源
最近更新 更多