Add Microsoft Dynamics CRM Online API Order Information

I use the following gem to connect to Microsoft Dyanmics CRM: https://github.com/TinderBox/dynamics_crm . I was able to connect and add contacts, links and several other things just fine. My problem is that I cannot figure out how to add order and order information. Here is the code that I use 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 is normal, but when I check the CRM server, there is no entry in the "Order Details" section. I also can’t understand how to send custom fields, I tried "new_shirtsize" => "XL", but I just got an error message that the "new_shirtsize" field does not exist for the salesorderdetail object.

+5
source share
2 answers

I can only guess, but I looked in the specification of the gem you mentioned. It seems that two parameters should be written like this:

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

Btw, you can make it a little more compact:

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

Two attempts:

  • Delete this line:

details['salesorderid']['Id'] = order.id

Reason: When creating a new record through the CRM API you do not need to specify an Id . CRM will generate this for you. This is the recommended approach when creating a new CRM record, rather than defining an Id .

  1. Make sure order.id is NOT NULL . I suspect the object is NULL .

Reason: When creating a new record using the CRM API you can (if you want) provide an Id , but you must verify that it has a valid GUID in the form (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), where x = is of HEX value .

+1
source

All Articles