This method creates a new sales invoice.
Parameter |
Type |
Description |
---|---|---|
salesInvoice |
The sales invoice object being created. |
|
context |
Specifies information about how the method will be called. |
|
policy |
Specifies the set of behaviors and behavior options to be applied during the operation. |
The following C# example creates a sales invoice. The example first populates the required DocumentTypeKey, CustomerKey, and BatchKey properties. The sales invoice uses a sales invoice line to specify the item and quantity sold. The sales invoice line requires the ItemKey, and Quantity properties to be populated. The sales invoice key and sales invoice line key are not populated. The CreateSalesInvoice operation automatically populates the empty sales invoice key and sales invoice line key with the next available invoice number. All other sales invoice properties are set to default values. The CreateSalesInvoice operation saves the new sales invoice.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; SalesInvoice salesInvoice; SalesDocumentTypeKey salesInvoiceType; CustomerKey customerKey; BatchKey batchKey; SalesInvoiceLine salesInvoiceLine; ItemKey invoiceItem; Quantity invoiceCount; Policy salesInvoiceCreatePolicy; // 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 invoice object salesInvoice = new SalesInvoice(); // Create a sales document type key for the sales invoice salesInvoiceType = new SalesDocumentTypeKey(); salesInvoiceType.Type = SalesDocumentType.Invoice; // Populate the document type key for the sales invoice salesInvoice.DocumentTypeKey = salesInvoiceType; // Create a customer key customerKey = new CustomerKey(); customerKey.Id = "AARONFIT0001"; // Set the customer key property of the sales invoice salesInvoice.CustomerKey = customerKey; // Create a batch key batchKey = new BatchKey(); batchKey.Id = "SALES INVOICES"; // Set the batch key property of the sales invoice object salesInvoice.BatchKey = batchKey; // Create a sales invoice line to specify the invoiced item salesInvoiceLine = new SalesInvoiceLine(); // Create an item key invoiceItem = new ItemKey(); invoiceItem.Id = "32X IDE"; // Set the item key property of the sales invoice line object salesInvoiceLine.ItemKey = invoiceItem; // Create a sales invoice quatity object invoiceCount = new Quantity(); invoiceCount.Value = 2; // Set the quantity of the sales invoice line object salesInvoiceLine.Quantity = invoiceCount; // Create an array of sales invoice lines // Initialize the array with the sales invoice line object SalesInvoiceLine[] invoiceLines = { salesInvoiceLine }; // Add the sales invoice line array to the sales line object salesInvoice.Lines = invoiceLines; // Get the create policy for the sales invoice object salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context); // Create the sales invoice wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy); } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; SalesInvoice salesInvoice; SalesDocumentTypeKey salesInvoiceType; CustomerKey customerKey; BatchKey batchKey; SalesInvoiceLine salesInvoiceLine; ItemKey invoiceItem; Quantity invoiceCount; Policy salesInvoiceCreatePolicy; // Create an instance of the service DynamicsGPClient wsDynamicsGP = new DynamicsGPClient(); // 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 invoice object salesInvoice = new SalesInvoice(); // Create a sales document type key for the sales invoice salesInvoiceType = new SalesDocumentTypeKey(); salesInvoiceType.Type = SalesDocumentType.Invoice; // Populate the document type key for the sales invoice salesInvoice.DocumentTypeKey = salesInvoiceType; // Create a customer key customerKey = new CustomerKey(); customerKey.Id = "AARONFIT0001"; // Set the customer key property of the sales invoice salesInvoice.CustomerKey = customerKey; // Create a batch key batchKey = new BatchKey(); batchKey.Id = "SALES INVOICES"; // Set the batch key property of the sales invoice object salesInvoice.BatchKey = batchKey; // Create a sales invoice line to specify the invoiced item salesInvoiceLine = new SalesInvoiceLine(); // Create an item key invoiceItem = new ItemKey(); invoiceItem.Id = "32X IDE"; // Set the item key property of the sales invoice line object salesInvoiceLine.ItemKey = invoiceItem; // Create a sales invoice quatity object invoiceCount = new Quantity(); invoiceCount.Value = 2; // Set the quantity of the sales invoice line object salesInvoiceLine.Quantity = invoiceCount; // Create an array of sales invoice lines // Initialize the array with the sales invoice line object SalesInvoiceLine[] invoiceLines = { salesInvoiceLine }; // Add the sales invoice line array to the sales line object salesInvoice.Lines = invoiceLines; // Get the create policy for the sales invoice object salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context); // Create the sales invoice wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }