添加订单详细信息Microsoft Dynamics CRM Online API

时间:2015-08-17 18:28:12

标签: ruby-on-rails ruby dynamics-crm-2011 dynamics-crm

我正在使用以下gem连接到Microsoft Dyanmics CRM:https://github.com/TinderBox/dynamics_crm。我能够连接并添加联系人,潜在客户和其他一些东西。我的问题是,我无法弄清楚如何添加订单和订单详情。以下是我用来创建订单明细的代码:

details = Hash.new
    details = {
        'quantity' => 1000.0,
        'productid' => product,
        'salesorderid' => DynamicsCRM::XML::EntityReference.new("salesorder", order.id),
        'uomid' => DynamicsCRM::XML::EntityReference.new("uom", 'F5AE673D-5D8E-E211-8AD0-78E3B5101E8F'),
        'createdon' => Time.now.getutc,
        'salesorderstatecode' => 1,
        'description' => 'This is just a test order',
    }
    orderDetail = client.create('salesorderdetail', details)

这样运行正常,但是当我检查CRM后端时,订单详细信息下没有记录。我也无法弄清楚如何发送自定义字段,我试过'new_shirtsize'=> 'XL',但我得到一个错误,即实体'salesorderdetail'不存在'new_shirtsize'字段。

2 个答案:

答案 0 :(得分:2)

我只能猜测,但我看了你提到的宝石的specs。看起来需要像这样编写两个参数:

details = {}
details['salesorderid'] = {}
details['salesorderid']['Id'] = order.id
details['salesorderid']['LogicalName'] = 'salesorder'
client.create('orderdetail', details)
不过,你可以把它变得更紧凑:

client.create('orderdetail', salesorderid: 
  {'Id' => order.id, 'LogicalName' => 'salesorder'} )

答案 1 :(得分:1)

要尝试两件事:

  1. 删除此行:
  2. details['salesorderid']['Id'] = order.id

    原因:通过CRM API创建新记录时,您不必提供IdCRM会为您生成此内容。这是创建新CRM记录时的推荐方法,而不是指定Id

    1. 检查order.idNOT NULL。我怀疑对象是NULL
    2. 原因:通过CRM API创建新记录时,可以(如果您确实愿意)提供Id,但您有检查它的有效GUID形式为(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),where x = is of HEX value