We aren't using eConnect, we are using the web services, which in turn use eConnect behind the scenes, of course. Here is the code that I'm using, based off of a sample that I found on the web. First, I get the invoice, so that I know what I'm returning (item, qty, etc) and then I populate a SalesReturn object. We are using the WS for other things, like saving invoices, creating customers, and more.
var client = new DynamicsGPSoapClient();
var salesDocumentKey = new SalesDocumentKey() {Id = invoiceNumber};
var context = buildContext();
var salesInvoiceResponse = client.GetSalesInvoiceByKey(new GetSalesInvoiceByKeyRequest(salesDocumentKey, context));
var salesInvoice = salesInvoiceResponse.GetSalesInvoiceByKeyResult;
var salesReturn = new SalesReturn();
salesReturn.DocumentTypeKey = new SalesDocumentTypeKey() { Type = SalesDocumentType.Return };
salesReturn.CustomerKey = new CustomerKey { Id = salesInvoice.CustomerKey.Id };
salesReturn.BatchKey = new BatchKey() { Id = string.Format("RTRN{0}", DateTime.Today.ToString("yyyyMMdd")) };
salesReturn.Date = DateTime.Today;
salesReturn.Type = SalesDocumentType.Return;
var returnedLines = new List<SalesReturnLine>();
foreach (var invoiceLine in salesInvoice.Lines)
{
var salesReturnLine = new SalesReturnLine();
salesReturnLine.ItemKey = new ItemKey() { Id = invoiceLine.ItemKey.Id };
var salesReturnQuantity = new SalesReturnQuantities();
salesReturnQuantity.ReturnedQuantity = new Quantity(){Value = invoiceLine.Quantity.Value, DecimalDigits = invoiceLine.Quantity.DecimalDigits};
salesReturnLine.ReturnQuantity = salesReturnQuantity;
salesReturnLine.Quantity = new Quantity() { Value = invoiceLine.Quantity.Value, DecimalDigits = invoiceLine.Quantity.DecimalDigits };
returnedLines.Add(salesReturnLine);
}
salesReturn.Lines = returnedLines.ToArray();
var returnPolicyRequest = new GetPolicyByOperationRequest("CreateSalesReturn", context);
var salesReturnCreatePolicy = client.GetPolicyByOperation(returnPolicyRequest).GetPolicyByOperationResult;
var createSalesReturnRequest = new CreateSalesReturnRequest(salesReturn, context, salesReturnCreatePolicy);
client.CreateSalesReturn(createSalesReturnRequest);
Thank you again for all the time you've already put in and will put in. I appreciate it.