web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Create sales Invoice in GP

(0) ShareShare
ReportReport
Posted on by 600

Hi All,

I am trying to create a sales invoice in GP using the web service. But I am always getting the "A validation exception has occurred".

Please help me to fix the issue. What are the minimum fields are required to create an Invoice.

For testing I have just copy paste the code given in this link http://msdn.microsoft.com/en-us/library/cc508459.aspx

But it is not working also, giving me the same error.

Regards,

Priya.

*This post is locked for comments

I have the same question (0)
  • jmawebtech Profile Picture
    585 on at

    Hi,

    You are likely missing a field. In the Windows start menu, go to Dynamics GP Web Service Exception Console. You should see the error there.

  • Priya Swain Profile Picture
    600 on at

    Hi Joseph,

    Thanks for the reply.

    I checked Dynamics GP Web Service Exception Console. I am getting the same validation exception in the console as well. It has no exception details.

    Is it possible to get a sample code to create an invoice using web service.

    Any help would be greatly appreciated.

    Regards,

    Priya

  • jmawebtech Profile Picture
    585 on at

    Hi,

    Assigning a default BillTo and ShipTo for the customer seems to resolve the problem.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using JMA.Plugin.MSDynamics.DynamicsGPService;

    namespace ConsoleApplication1

    {

       class Program

       {

           static void Main(string[] args)

           {

               CompanyKey companyKey;

               Context context;

               SalesOrder salesOrder;

               SalesDocumentTypeKey salesOrderType;

               CustomerKey customerKey;

               BatchKey batchKey;

               SalesOrderLine salesOrderLine;

               ItemKey orderedItem;

               Quantity orderedAmount;

               Policy salesOrderCreatePolicy;

              // CreateItem();

              // CreatePriceListForItem();

              // CreateItemWarehouse();

               //CreateCustomer();

               //CreateCustomerAddress();

               // Create an instance of the service

               DynamicsGP wsDynamicsGP = new DynamicsGP();

               // Be sure the default credentials are used

               wsDynamicsGP.UseDefaultCredentials = true;

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context object

               context.OrganizationKey = (OrganizationKey)companyKey;

               //var ws = wsDynamicsGP.GetWarehouseList(new WarehouseCriteria(), context).FirstOrDefault();

               //var ws = wsDynamicsGP.GetPriceLevelList(new PriceLevelCriteria(), context);

               Policy p = wsDynamicsGP.GetPolicyByOperation("DeleteSalesOrder", context);

               wsDynamicsGP.DeleteSalesOrder(new SalesDocumentKey { Id = "ORDST2239" }, context, p);

               // Create a sales order object

               salesOrder = new SalesOrder();

               //var cust = wsDynamicsGP.GetCustomerByKey(new CustomerKey { Id = "ADMINISTRATORGL" }, context);

               // 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 = "ADMINISTRATORGL";

               // Set the customer key property of the sales order object

               salesOrder.CustomerKey = customerKey;

               // Create a batch key

               batchKey = new BatchKey();

               batchKey.Id = "SALES ORDERS";

               // 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 = "ADI123";

               // 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;

               salesOrderLine.WarehouseKey = new WarehouseKey { Id = "NORTH" };

               // 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);

               salesOrder.PaymentAmount = new MoneyAmount { Value = 399.96M};

               // Create the sales order

               wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);

           }

           static void CreateCustomer()

           {

               CompanyKey companyKey;

               Context context;

               Customer customer;

               CustomerKey customerKey;

               Policy customerPolicy;

               // Create an instance of the service

               DynamicsGP wsDynamicsGP = new DynamicsGP();

               // Be sure that default credentials are being used

               wsDynamicsGP.UseDefaultCredentials = true;

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context

               context.OrganizationKey = (OrganizationKey)companyKey;

               // Create a new customer object

               customer = new Customer();

               // Create a customer key

               customerKey = new CustomerKey();

               customerKey.Id = "ADMINISTRATORGL";

               customer.Key = customerKey;

               //assign unlimited class

               CustomerCreditLimit cc = new CustomerCreditLimit();

               cc.Item = //what do I put into item?

               cc.Period = 10;

               cc.PeriodAmount = new MoneyAmount { Currency = "Z-US$", DecimalDigits = 4, Value = 20000 };

               customer.ClassKey = new CustomerClassKey { Id = "USA-ILMO-T1" };

               // Set properties for the new customer

               customer.Name = "Global Admin";

               // Get the create policy for the customer

               customerPolicy = wsDynamicsGP.GetPolicyByOperation("CreateCustomer", context);

               // Create the customer

               wsDynamicsGP.CreateCustomer(customer, context, customerPolicy);

           }

           static void CreateCustomerAddress()

           {

               CompanyKey companyKey;

               Context context;

               CustomerKey customerKey;

               CustomerAddressKey customerAddressKey;

               CustomerAddress customerAddress;

               Policy customerAddressCreatePolicy;

               // Create an instance of the service

               DynamicsGP wsDynamicsGP = new DynamicsGP();

               // Be sure the default credentials are used

               wsDynamicsGP.UseDefaultCredentials = true;

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context object

               context.OrganizationKey = (OrganizationKey)companyKey;

               // Create a customer key to specify the customer

               customerKey = new CustomerKey();

               customerKey.Id = "ADMINISTRATORGL";

               // Create a customer address key

               customerAddressKey = new CustomerAddressKey();

               customerAddressKey.CustomerKey = customerKey;

               customerAddressKey.Id = "BILLING2";

               // Create a customer address object

               customerAddress = new CustomerAddress();

               customerAddress.Key = customerAddressKey;

               customerAddress.Name = "Global Administrator";

               // Populate properties with address information

               customerAddress.Line1 = "11403 45 St. South";

               customerAddress.Line2 = "Billing Dept.";

               customerAddress.City = "Chicago";

               customerAddress.State = "IL";

               customerAddress.CountryRegion = "USA";

               // Get the create policy for the customer address

               customerAddressCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateCustomerAddress",

               context);

               // Create the customer address

               wsDynamicsGP.CreateCustomerAddress(customerAddress, context, customerAddressCreatePolicy);

               Customer cu = wsDynamicsGP.GetCustomerByKey(customerKey, context);

               cu.BillToAddressKey = customerAddressKey;

               cu.ShipToAddressKey = customerAddressKey;

              var p =  wsDynamicsGP.GetPolicyByOperation("UpdateCustomer", context);

              wsDynamicsGP.UpdateCustomer(cu, context, p);

           }

           static void CreatePriceListForItem()

           {

               CompanyKey companyKey;

               Context context;

               ItemKey itemKey;

               PriceLevelKey priceLevelKey;

               CurrencyKey currencyKey;

               PricingKey pricingKey;

               Pricing pricing;

               PricingDetail pricingDetail;

               PricingDetailKey pricingDetailKey;

               Quantity toQuantity;

               PricingDetailPrice detailPrice;

               MoneyAmount priceAmount;

               Policy pricingCreatePolicy;

               // Create an instance of the service

               DynamicsGP wsDynamicsGP = new DynamicsGP();

               // Be sure the default credentials are used

               wsDynamicsGP.UseDefaultCredentials = true;

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context object

               context.OrganizationKey = (OrganizationKey)companyKey;

               // Create an item key to identify the item

               itemKey = new ItemKey();

               itemKey.Id = "ADI123";

               // Create a price level key

               priceLevelKey = new PriceLevelKey();

               priceLevelKey.Id = "RETAIL";

               // Create a currency key

               currencyKey = new CurrencyKey();

               currencyKey.ISOCode = "USD";

               // Create a pricing key object and populate its key properties

               pricingKey = new PricingKey();

               pricingKey.ItemKey = itemKey;

               pricingKey.PriceLevelKey = priceLevelKey;

               pricingKey.CurrencyKey = currencyKey;

               pricingKey.UofM = "EACH";

               // Create a price level object

               pricing = new Pricing();

               // Populate the pricing object key

               pricing.Key = pricingKey;

               // Create a pricing detail object

               pricingDetail = new PricingDetail();

               // Create a pricing detail key

               pricingDetailKey = new PricingDetailKey();

               // Populate the pricing detail key with the pricing key

               pricingDetailKey.PricingKey = pricingKey;

               // Create a quantity object

               toQuantity = new Quantity();

               // Populate the quantity objects value property with the maximum value

               toQuantity.Value = 999999999999M;

               // Populate the pricing detail key ToQuantity property

               pricingDetailKey.ToQuantity = toQuantity;

               // Populate the pricing detail key

               pricingDetail.Key = pricingDetailKey;

               // Create a pricing detail price object

               detailPrice = new PricingDetailPrice();

               // Create a money amount object to specify the price and currency

               priceAmount = new MoneyAmount();

               priceAmount.Value = 5m;

               priceAmount.Currency = "USD";

               // Populate the pricing detail price item with the amount object

               detailPrice.Item = priceAmount;

               // Populate the pricing detail object's UofMPrice with the pricing detail price object

               pricingDetail.UofMPrice = detailPrice;

               // Create an array for the pricing detail objects

               PricingDetail[] pricingDetails = { pricingDetail };

               // Add the array of pricing details to the pricing object

               pricing.Details = pricingDetails;

               // Get the create policy for price level

               pricingCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePricing", context);

               // Create the pricing object

               wsDynamicsGP.CreatePricing(pricing, context, pricingCreatePolicy);

           }

           static void CreateItemWarehouse()

           {

               CompanyKey companyKey;

               Context context;

               ItemKey itemKey;

               WarehouseKey warehouseKey;

               ItemWarehouseKey itemWarehouseKey;

               ItemWarehouse itemWarehouse;

               Policy itemWarehouseCreatePolicy;

               // Create an instance of the service

               DynamicsGP wsDynamicsGP = new DynamicsGP();

               // Be sure the default credentials are used

               wsDynamicsGP.UseDefaultCredentials = true;

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context object

               context.OrganizationKey = (OrganizationKey)companyKey;

               // Create an item warehouse object

               itemWarehouse = new ItemWarehouse();

               // Create an item key to specify the item

               itemKey = new ItemKey();

               itemKey.Id = "ADI123";

               // Create a warehouse key to specify the warehouse

               warehouseKey = new WarehouseKey();

               warehouseKey.Id = "NORTH";

               // Create an item warehouse key

               itemWarehouseKey = new ItemWarehouseKey();

               itemWarehouseKey.ItemKey = itemKey;

               itemWarehouseKey.WarehouseKey = warehouseKey;

               // Populate the item warehouse key property

               itemWarehouse.Key = itemWarehouseKey;

               // Get the create policy for item warehouse

               itemWarehouseCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateItemWarehouse", context);

               // Create the item warehouse

               wsDynamicsGP.CreateItemWarehouse(itemWarehouse, context, itemWarehouseCreatePolicy);

           }

           static void CreateItem()

           {

               CompanyKey companyKey;

               Context context;

               ItemKey itemKey;

               UofMScheduleKey unitOfMeasureKey;

               SalesItem salesItem;

               Policy salesItemCreatePolicy;

               // Create an instance of the service

               DynamicsGP wsDynamicsGP = new DynamicsGP();

               // Be sure the default credentials are used

               wsDynamicsGP.UseDefaultCredentials = true;

               // Create a context with which to call the service

               context = new Context();

               // Specify which company to use (sample company)

               companyKey = new CompanyKey();

               companyKey.Id = (-1);

               // Set up the context object

               context.OrganizationKey = (OrganizationKey)companyKey;

               // Create a sales item object

               salesItem = new SalesItem();

               // Create a sales item key object to identify the sales item

               itemKey = new ItemKey();

               itemKey.Id = "ADI123";

               // Populate the sales item key property

               salesItem.Key = itemKey;

               WarehouseKey warehouseKey = wsDynamicsGP.GetWarehouseList(new WarehouseCriteria(), context).FirstOrDefault().Key;

               ItemWarehouseKey itemWarehouseKey = new ItemWarehouseKey();

               itemWarehouseKey.ItemKey = itemKey;

               itemWarehouseKey.WarehouseKey = warehouseKey;

               salesItem.DefaultPriceLevelKey = wsDynamicsGP.GetPriceLevelList(new PriceLevelCriteria(), context).FirstOrDefault().Key;

               salesItem.DefaultWarehouseKey = warehouseKey;

               // Populate the description property

               salesItem.Description = "Test inventory item 05";

               // Create a unit of measure schedule key

               unitOfMeasureKey = new UofMScheduleKey();

               unitOfMeasureKey.Id = "EACH";

               // Populate the unit of measure property

               salesItem.UofMScheduleKey = unitOfMeasureKey;

               // Get the create policy for sales item

               salesItemCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesItem", context);

               // Create the sales item

               wsDynamicsGP.CreateSalesItem(salesItem, context, salesItemCreatePolicy);

           }

       }

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans