Hello. I had previously posted a forum question over at https://community.dynamics.com/product/gp/f/32/p/100665/191424.aspx#191424 but after someone asked me to post the XML that was tried against GP, I broke the forum (I'm guessing it was too much data).
I'm looking to create a return from an invoice. I have found a few resources for help online and modified one in the code that we are using. That code is here:
var client = new DynamicsGPSoapClient();
var salesDocumentKey = new SalesDocumentKey() {Id = invoiceNumber};
var context = buildContext(); // we use this method whenever we have WS calls
var salesInvoiceResponse = client.GetSalesInvoiceByKey(new GetSalesInvoiceByKeyRequest(salesDocumentKey, context));
// this method is successful and returns a salesdocument with data
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)
{
// basing this on example I found and these were the only fields populated
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();
// Get the create policy for sales returns
var returnPolicyRequest = new GetPolicyByOperationRequest("CreateSalesReturn", context);
var salesReturnCreatePolicy = client.GetPolicyByOperation(returnPolicyRequest).GetPolicyByOperationResult;
var createSalesReturnRequest = new CreateSalesReturnRequest(salesReturn, context, salesReturnCreatePolicy);
client.CreateSalesReturn(createSalesReturnRequest);
This fails with a generic message that is also in the Dynamics.dbo.WSExceptionLog table. The message is "A validation exception has occurred. "
I went into that WSExceptionLog table and pulled out the request XML as was requested on the other thread, but this time I put it in a GitHub Gist so I wouldn't break the forum again. It is located here:
https://gist.github.com/PeteShearer/bcc7c04d51704b232d23
I don't know how to check what validation rules might be in effect for SalesReturns in GP, so if it isn't something obvious, could you please tell me (or point to somewhere teaching me) how to find out what might be required?
A side note is that we also can't view our Exceptions in the MMC snap-in, getting a security exception. I've tried all of the fixes I've found on various forums, to no avail. So, if you also have another place to find exceptions in more detail, I'd greatly appreciate it.
Thanks in advance for your help.
*This post is locked for comments