Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Dynamics GP Web Service - Create Sales Return Validation Errors

Posted on by 380

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

  • RonCarter Profile Picture
    RonCarter 380 on at
    Re: Dynamics GP Web Service - Create Sales Return Validation Errors

    Grant, 

     

    Crap.  It totally was the salesReturn.Key.  I feel like an idiot.  Now I have these validation errors, which seem reasonable.  I'm going to accept your post as the answer.

    A validation exception has occurred.

    Validation Errors:

    - ItemKey does not exist.

    - A validation error has occurred.

    - The U of M for the item is not specified in the item price list as the default selling U of M.

    - U of M does not exist for the Unit of Measure Schedule being used.

    - PriceListKey is blank. It must be passed in or a default must exist for the transaction.

  • Verified answer
    Re: Dynamics GP Web Service - Create Sales Return Validation Errors

    Ah, my post was too late. That's fine, I'll try to assist with the additional data. Have you tried setting the

    salesReturn.Key property?

    Something like this might help:

    string ID = "RTN113"; //your own ID here, of course

    SalesDocumentKey salesDocKey = new SalesDocumentKey();

    salesDocKey.Id = ID;

    salesReturn.Key = salesDocKey;

    I hope this helps!

  • Re: Dynamics GP Web Service - Create Sales Return Validation Errors

    I'd suggest checking your Event Viewer--all "Validation" exceptions should also be logged to the eConnect or Dynamics event logs (on the WebServices server, of course).

    Good luck!

    Grant

    This posting is provided "AS IS" with no warranties, and confers no rights.

  • RonCarter Profile Picture
    RonCarter 380 on at
    Re: Dynamics GP Web Service - Create Sales Return Validation Errors

    Thank you both Steve and Samdip for quick responses.  I was able to go into the Event Viewer and find this exception for a request:

     

    Microsoft.GreatPlains.eConnect Version=10.0.0.0

    Microsoft.Dynamics.GP.eConnect

     

    Please supply the SOPTYPE and DOCID in the taSopHdrIvcInsert if not passing a SOPNUMBE.

       at Microsoft.Dynamics.GP.eConnect.eConnectMethods.ExecStoredProcedures(String xml)

       at Microsoft.Dynamics.GP.eConnect.eConnectMethods.eConnect_EntryPoint(String ConnectionString, ConnectionStringType ConnectionType, String sXML, SchemaValidationType ValidationType, String eConnectSchema)

     

     

    We are using GP 10, and though the exception mentions eConnect there, we are - as my code sample mentions - using Dynamics WS (which I understand calls eConnect under the covers).

     

    I thought I was setting SOPTYPE by setting the type in one of these two places from my original code sample:

    salesReturn.DocumentTypeKey = new SalesDocumentTypeKey() { Type = SalesDocumentType.Return };

    salesReturn.Type = SalesDocumentType.Return;

     

    As far as DOCID, the documentation says that is for "Document Id" (super helpful!).  However, Sales Return does not have a DOCID, DocumentId, DocumentNumber, SOPNUMBE, or SopNumber property.  It only has MasterNumber, which is an int.  That is a little weird to me because SOPNUMBE can be a string, so this didn't seem right. 

     

    Regardless, I set salesReturn.MasterNumber = 9999 and submitted and got the same error as I pasted above.

     

    Does anyone have any information or real examples of this that could be helpful?

     

    Thanks again.

  • Steve Kubis Profile Picture
    Steve Kubis on at
    Re: Dynamics GP Web Service - Create Sales Return Validation Errors

    The easiest way to view the exceptions is to use the Exception Management Console. But, you apparently don't have access to that. :-(

    Your web service code can retrieve the validation exception(s) that occurred. These would be the same exceptions that are logged in the Exception Management Console. This topic on MSDN describes how you would do this:

    msdn.microsoft.com/.../ff623150.aspx

    You don't say what version of GP you're using, so I'll guess that its GP 2010. From your code, it looks like you're using the legacy endpoint. In the topic I mentioned, you'll see there's a slightly different approach for the native endpoint vs. the legacy endpoint.

    If you're using an older version of GP, then you'll have to search for that same topic in the Web Service Programmer's Guide. It will explain this same technique for the older .asmx-based web service.

    Then you'll know what the actual validation error is.

    Steve

  • sandipdjadhav Profile Picture
    sandipdjadhav 18,265 on at
    Re: Dynamics GP Web Service - Create Sales Return Validation Errors

    Ron,

    Login with login Id which is used to install Web Services. if you cannot access Web Service Excepiton MMC snap in then goto event viewer and check eConnect for more details.

    Let me know how it goes.

    Thanks

    Sandip

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans