CRM 网站 api 随过滤器展开 - 内部连接还是左侧连接?

CRM web api expand along with filter - inner join or left join?

我正在尝试使用网络 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,但是展开过滤器只得到null。如何消除主结果中扩展实体过滤后的空结果?

"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 的结果。我还缺少其他简单的方法吗?

来自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 来实现此目的。

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

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

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