我正在使用以下gem连接到Microsoft Dynamics 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',但是我只是得到一个错误,'new_shirtsize’字段对于实体'salesorderdetail‘不存在。
发布于 2015-08-20 08:45:17
我只能猜测,但我看了一下你提到的宝石的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'} )
发布于 2015-08-21 05:43:18
有两件事可以尝试:
details['salesorderid']['Id'] = order.id
原因:通过CRM API
创建新记录时,您不必提供Id
。CRM
将为您生成此代码。这是创建新CRM
记录时的推荐方法,而不是指定Id
。
order.id
是否为NOT NULL
。我怀疑这个对象是NULL
.原因:当您通过CRM API
创建新记录时,您可以(如果您确实想要)提供Id
,但您必须检查它是否具有(xxxxxxxx-xxxx-xxxxxxxxxxxx),where x = is of HEX value
形式的有效GUID
。
https://stackoverflow.com/questions/32057253
复制