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

MS Dynamics 365 CRM中salesorder对象customerid无法展开问题

问题描述

需要获取邮箱为customer_email@example.com的客户的订单列表,执行了以下API请求:

GET [Organization URI]/api/data/v9.1/salesorders?$select=name,salesorderid&$expand=customerid($select=fullname,emailaddress1)&$filter=customerid/emailaddress1 eq 'customer_email@example.com'

收到错误响应:

{
    "error": {
        "code": "0x0",
        "message": "Could not find a property named 'customerid' on type 'Microsoft.Dynamics.CRM.salesorder'."
    }
}

已知salesorders对象中存在_customerid_value字段,需解决如何正确获取目标订单列表的问题。

解决方案

原因分析

SalesOrder实体的customerid是多态查找字段,可关联Account(企业客户)或Contact(联系人)实体,直接通过customerid/emailaddress1过滤会因多态类型不明确导致报错。_customerid_value仅存储关联实体的GUID,无法直接用来过滤邮箱,需调整查询逻辑。

正确API请求

根据目标客户的类型,可选择以下方式:

1. 兼容两种客户类型的查询

如果不确定目标邮箱属于企业客户还是联系人,可同时过滤两种实体类型:

GET [Organization URI]/api/data/v9.1/salesorders?$select=name,salesorderid&$expand=customerid($select=fullname,emailaddress1)&$filter=customerid/contact/emailaddress1 eq 'customer_email@example.com' or customerid/account/emailaddress1 eq 'customer_email@example.com'

2. 针对单一类型的精准查询

若明确目标邮箱属于联系人:

GET [Organization URI]/api/data/v9.1/salesorders?$select=name,salesorderid&$expand=contactid($select=fullname,emailaddress1)&$filter=contactid/emailaddress1 eq 'customer_email@example.com'

若明确属于企业客户:

GET [Organization URI]/api/data/v9.1/salesorders?$select=name,salesorderid&$expand=accountid($select=name,emailaddress1)&$filter=accountid/emailaddress1 eq 'customer_email@example.com'

补充说明

  • 多态查找字段的导航属性在OData查询中需明确指定关联实体类型(如customerid/contact、customerid/account),否则系统无法识别对应属性。
  • 若要使用_customerid_value查询,需先通过邮箱获取对应Account/Contact的GUID,再执行以下请求:
GET [Organization URI]/api/data/v9.1/salesorders?$select=name,salesorderid&$expand=customerid($select=fullname,emailaddress1)&$filter=_customerid_value eq '<目标实体GUID>'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 12:52:13