Microsoft Dynamics CRM 2015 - 使用OData API创建实体

时间:2017-08-15 21:16:12

标签: dynamics-crm microsoft-dynamics dynamics-crm-2015 microsoft-dynamics-webapi dynamics-crm-odata

不确定以下请求错误的原因如下:

  

处理请求流时出错。请求应该是有效的顶级资源对象。

请求(由于显而易见的原因,某些细节已被混淆):

POST http://someUrl.com/someUrl/XRMServices/2011/OrganizationData.svc/someSet HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Accept-Encoding: gzip, deflate
Content-Length: 387
Host: someUrl.com

{
    "paymentid": {
        "Id": "00e3f661-8d28-e321-896e-00155dfd1d05",
        "LogicalName": "payment"
    },
    "invoiceid": {
        "Id": "00e3f661-8d28-e411-896e-00155dfd1d05",
        "LogicalName": "invoice"
    },
    "AppliedAmount": 1317.53000,
    "name": "Payment Applied",
    "postingstatus": "Posted",
    "transactioncurrencyid": {
        "Id": "80870a9b-329e-d421-8a22-00155d025001",
        "LogicalName": "transactionCurrency"
    }
}

所有逻辑名称都是通过运行以下查询得出的:

select
    LogicalName
from 
    NHLPA_MSCRM.dbo.EntityView
where
    BaseTableName = 'paymentbase' -- | invoicebase | transactioncurrencybase

1 个答案:

答案 0 :(得分:0)

  

摘要:使用OrganizationData.svc/someSet网址获取现有实体的列表,为必要的JSON结构提供完美参考(减去_metaData属性)

所以问题最终变得非常简单。

实体someSet不是问题所在,表示能够毫无问题地访问http://someUrl.com/someUrl/XRMServices/2011/OrganizationData‌​.svc/someSet

进一步深入研究内部逻辑实体(支付,发票,交易货币)。如上所述,这些逻辑名称来自数据库,它与实体设置页面匹配(下图)。

enter image description here

但是,以下所有网址都无法解决:

  • http://someUrl.com/someUrl/XRMServices/2011/OrganizationData‌​.svc/paymentSet
  • http://someUrl.com/someUrl/XRMServices/2011/OrganizationData‌​.svc/invoiceSet
  • http://someUrl.com/someUrl/XRMServices/2011/OrganizationData‌​.svc/transactionCurrencySet

问题在于,尽管在您找到实体的逻辑名称的所有地方都小写,但第一个字母实际上需要大写,如:

  • http://someUrl.com/someUrl/XRMServices/2011/OrganizationData‌​.svc/PaymentSet
  • http://someUrl.com/someUrl/XRMServices/2011/OrganizationData‌​.svc/InvoiceSet
  • http://someUrl.com/someUrl/XRMServices/2011/OrganizationData‌​.svc/TransactionCurrencySet

工作负载:

{
    "paymentid": {
        "Id": "00e3f661-8d28-e321-896e-00155dfd1d05",
        "LogicalName": "Payment"
    },
    "invoiceid": {
        "Id": "00e3f661-8d28-e411-896e-00155dfd1d05",
        "LogicalName": "Invoice"
    },
    "AppliedAmount": 1317.53000,
    "name": "Payment Applied",
    "postingstatus": "Posted",
    "TransactionCurrencyId": {
        "Id": "80870a9b-329e-d421-8a22-00155d025001",
        "LogicalName": "TransactionCurrency"
    }
}