Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

.NET Insert new salesOrder

(0) ShareShare
ReportReport
Posted on by 390

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

  • sandipdjadhav Profile Picture
    sandipdjadhav 18,267 on at
    Re: .NET Insert new salesOrder

    Hi,

    Can you check in web server - WebService Exception console to see details about your error and in event viewer give you error details too on same server.

    Please post details error to see exactly whats going on.

    Thansk

    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans