Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

CreateSalesOrder: A validation exception has occurred with no details

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi. I am trying to create sales order. This is my code:

            DynamicsGP service = new DynamicsGP();

            service.Credentials = new System.Net.NetworkCredential("user", "password", "domain");

            Context context = new Context();

            context.OrganizationKey = new CompanyKey { Id = 2 };

            SalesOrder salesOrder = new SalesOrder();

            salesOrder.Type = SalesDocumentType.Order;
            salesOrder.DocumentTypeKey = new SalesDocumentTypeKey { Type = SalesDocumentType.Order };
            salesOrder.SalespersonKey = new SalespersonKey { Id = "ALOPEZ" };
            salesOrder.CustomerKey = new CustomerKey { Id = "0802612408" };
            salesOrder.PaymentTermsKey = new PaymentTermsKey { Id = "07 DIAS" };
            salesOrder.Comment = "Hello world";
            salesOrder.CreatedBy = "ALOPEZ         ";
            salesOrder.CreatedDate = DateTime.Now.Date;
            salesOrder.BatchKey = new BatchKey { Id = "BATCH_20140507" };
            salesOrder.ActualShipDate = DateTime.Now.AddDays(1);
            salesOrder.BillToAddressKey = new CustomerAddressKey { CustomerKey = new CustomerKey { Id = "0802612408" }, Id = "PRINCIPAL" };
            salesOrder.CreatedDate = DateTime.Now;
            salesOrder.Date = DateTime.Now;
            salesOrder.Note = "Note";

            SalesOrderLine salesOrderLine = new SalesOrderLine();

            salesOrderLine.ItemKey = new ItemKey { Id = "TY.9.SF" };
            salesOrderLine.Quantity = new Quantity { Value = 1 };
            salesOrderLine.UnitPrice = new MoneyAmount { Currency = "USD", Value = 12.38M };
            salesOrderLine.WarehouseKey = new WarehouseKey { Id = "01 MATRIZ" };

            salesOrder.Lines = new SalesOrderLine[] {salesOrderLine};

            Policy salesOrderCreatePolicy = service.GetPolicyByOperation("CreateSalesOrder", context);

            service.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);

Trying to send and receive error: "A validation exception has occurred.". But it comes with no any additional details. Only this message, Inside Dynamics Exceptions Console - same, no details, just this message.

With order I almost trying everything: omit parameters, define parameters, but still get this message.

Anyone knows what configuration can cause this error?

Thanks.

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CreateSalesOrder: A validation exception has occurred with no details

    Solved this. Problem was that DocumentTypeKey must be provided with Id. Which this for company where I am doing integration is MVFLO-PD-001

    So line

       salesOrder.DocumentTypeKey = new SalesDocumentTypeKey { Type = SalesDocumentType.Order };

    Should be:

       salesOrder.DocumentTypeKey = new SalesDocumentTypeKey { Type = SalesDocumentType.Order, Id = "MVFLO-PD-001" };

    This is is only change I had to made to code.

    To figure it out I had to call stored procedure taSopHdrIvcInsert directly, so this procedure returned to me error code by which I undestood what is wrong.

    I just disappointed that Web Service cannot tell me what is exactly wrong. I found examples in Internet in which Id of DocumentTypeKey wasn't provided, so I thought it will works without it.

    Anyway, question is closed.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CreateSalesOrder: A validation exception has occurred with no details

    Hi Alexey,

    while passing the parameters please make sure that you have trim those values and also the passed parameters are already existing in GP.

    as Tom mentioned, please try to create the sales order manually and check the same error appears or not.

  • Suggested answer
    Tom Mathew Profile Picture
    Tom Mathew 1,750 on at
    RE: CreateSalesOrder: A validation exception has occurred with no details

    Usually these kind of error comes when something happens disturbing the application logic.......

    1. Is the batch already created..

    2. Missing any required fields etc......

    Try creating the sales order manually through GP form with the same set of information and check whether it is giving any error or not.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CreateSalesOrder: A validation exception has occurred with no details

    Now I am trying to send this:

                SalesOrder salesOrder = new SalesOrder();

                salesOrder.Type = SalesDocumentType.Order;
                salesOrder.DocumentTypeKey = new SalesDocumentTypeKey { Type = SalesDocumentType.Order };
                salesOrder.CustomerKey = new CustomerKey { Id = "0802612408" };
                salesOrder.WarehouseKey = new WarehouseKey { Id = "01 MATRIZ" };

                SalesOrderLine salesOrderLine = new SalesOrderLine();

                salesOrderLine.ItemKey = new ItemKey { Id = "005" };
                salesOrderLine.Quantity = new Quantity { Value = 1 };

                salesOrder.Lines = new SalesOrderLine[] {salesOrderLine};

                Policy salesOrderCreatePolicy = service.GetPolicyByOperation("CreateSalesOrder", context);

                service.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);
     

    Got same error. Pretty sure customer, storage and item I defined exists.

    I changed regional settings of my computer to what server has - not helping.

  • Tom Mathew Profile Picture
    Tom Mathew 1,750 on at
    RE: CreateSalesOrder: A validation exception has occurred with no details

    Just check whether you are passing any values which doesn't exist or not defined in GP. Along with that check the regional settings especially the date format.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans