I have a new company with id 7.
After that I created a new batch for my company (id=7), a new customer for this company and a new Item. After that i used the sample from here: http://msdn.microsoft.com/en-us/library/cc508441.aspx and replaced these datas. But when i am running i am getting "A validation exception has occurred." Why? I verify all ids and they exist (customerKey, batchId and company).
This is the code:
//creating the dynamic client
context = new Context();
// Specify which company to use (sample company)
companyKey = new CompanyKey();
companyKey.Id = 7;
// Set up the context object
context.OrganizationKey = (OrganizationKey)companyKey;
// Create a sales order object
salesOrder = new SalesOrder();
// Create a sales document type key for the sales order
salesOrderType = new SalesDocumentTypeKey();
salesOrderType.Type = SalesDocumentType.Order;
// Populate the document type key of the sales order object
salesOrder.DocumentTypeKey = salesOrderType;
// Create a customer key
customerKey = new CustomerKey();
customerKey.Id = "1";
// Set the customer key property of the sales order object
salesOrder.CustomerKey = customerKey;
// Create a batch key
batchKey = new BatchKey();
batchKey.Id = "BATCHID";
// Set the batch key property of the sales order object
salesOrder.BatchKey = batchKey;
// Create a sales order line to specify the ordered item
salesOrderLine = new SalesOrderLine();
// Create an item key
orderedItem = new ItemKey();
orderedItem.Id = "10371";
// Set the item key property of the sales order line object
salesOrderLine.ItemKey = orderedItem;
// Create a sales order quantity object
orderedAmount = new Quantity();
orderedAmount.Value = 4;
// Set the quantity of the sales order line object
salesOrderLine.Quantity = orderedAmount;
// Create an array of sales order lines
// Initialize the array with sales order line object
SalesOrderLine[] orders = { salesOrderLine };
// Add the sales order line array to the sales order
salesOrder.Lines = orders;
// Get the create policy for the sales order object
salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context);
// Create the sales order
wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);
*This post is locked for comments