Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add order details Microsoft Dynamics CRM Online API

I'm using the following gem to connect to Microsoft Dynamics CRM: https://github.com/TinderBox/dynamics_crm. I was able to connect and add contacts, leads and a few other things just fine. My problem is, I can't figure out how to add an order and order details. Here is the code I am using to create an order detail:

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)

This runs fine, but when I check in the CRM backend, there is no record under Order Details. I also can't figure out how to send custom fields, I have tried 'new_shirtsize' => 'XL', but I just get an error that the field 'new_shirtsize' doesn't exist for the entity 'salesorderdetail'.

like image 671
Kyle Avatar asked Oct 20 '22 04:10

Kyle


1 Answers

I can only guess, but I had a look in the specs of the gem you mentioned. Looks like the two parameters need to be written like so:

details = {}
details['salesorderid'] = {}
details['salesorderid']['Id'] = order.id
details['salesorderid']['LogicalName'] = 'salesorder'
client.create('orderdetail', details)

Btw, you can make this a little more compact:

client.create('orderdetail', salesorderid: 
  {'Id' => order.id, 'LogicalName' => 'salesorder'} )
like image 159
smallbutton Avatar answered Oct 22 '22 03:10

smallbutton