This method creates a new purchase invoice document.
Parameter |
Type |
Description |
---|---|---|
purchaseInvoice |
The purchase 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 new purchase invoice document with the key “RCT4065”. The example demonstrates setting the purchase invoice document’s required key, vendor key, and vendor document number properties. The example uses a single purchase invoice line to specify purchase order, quantity, and item information. All other properties use default values.
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; PurchaseTransactionKey purchaseInvoiceKey; VendorKey vendorKey; PurchaseInvoice purchaseInvoice; PurchaseInvoiceLine purchaseInvoiceLine; PurchaseTransactionKey purchaseOrderKey; Quantity purchaseInvoiceQuantity; Policy purchaseInvoiceCreatePolicy; // 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 purchase transaction key to identify the purchase invoice purchaseInvoiceKey = new PurchaseTransactionKey(); purchaseInvoiceKey.Id = "RCT4065"; // Create a vendor key to specify the vendor vendorKey = new VendorKey(); vendorKey.Id = "ADVANCED0001"; // Create the purchase invoice object purchaseInvoice = new PurchaseInvoice(); // Populate the required properties purchaseInvoice.Key = purchaseInvoiceKey; purchaseInvoice.VendorKey = vendorKey; purchaseInvoice.VendorDocumentNumber = "AD2223454"; // Create a purchase invoice line object for the purchase invoice object purchaseInvoiceLine = new PurchaseInvoiceLine(); // Create a purchase order key to specify the purchase order purchaseOrderKey = new PurchaseTransactionKey(); purchaseOrderKey.Id = "PO0997"; // Add the purchase order key to the purchase invoice line purchaseInvoiceLine.PurchaseOrderKey = purchaseOrderKey; // Set the vendor item number property for the purchase invoice line purchaseInvoiceLine.VendorItemNumber = "ATT-53BK"; // Create a quantity object to specify the quantity of an item purchaseInvoiceQuantity = new Quantity(); purchaseInvoiceQuantity.Value = 1; // Populate the quantity property of the purchase invoice line object purchaseInvoiceLine.QuantityInvoiced = purchaseInvoiceQuantity; // Create an array to hold the purchase line object PurchaseInvoiceLine[] lines = { purchaseInvoiceLine }; // Add the array of purchase invoice lines to the purchase invoice object purchaseInvoice.Lines = lines; // Get the create policy for purchase invoices purchaseInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation( "CreatePurchaseInvoice", context); // Create the purchase invoice wsDynamicsGP.CreatePurchaseInvoice(purchaseInvoice, context, purchaseInvoiceCreatePolicy); } } }
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; PurchaseTransactionKey purchaseInvoiceKey; VendorKey vendorKey; PurchaseInvoice purchaseInvoice; PurchaseInvoiceLine purchaseInvoiceLine; PurchaseTransactionKey purchaseOrderKey; Quantity purchaseInvoiceQuantity; Policy purchaseInvoiceCreatePolicy; // 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 purchase transaction key to identify the purchase invoice purchaseInvoiceKey = new PurchaseTransactionKey(); purchaseInvoiceKey.Id = "RCT4065"; // Create a vendor key to specify the vendor vendorKey = new VendorKey(); vendorKey.Id = "ADVANCED0001"; // Create the purchase invoice object purchaseInvoice = new PurchaseInvoice(); // Populate the required properties purchaseInvoice.Key = purchaseInvoiceKey; purchaseInvoice.VendorKey = vendorKey; purchaseInvoice.VendorDocumentNumber = "AD2223454"; // Create a purchase invoice line object for the purchase invoice object purchaseInvoiceLine = new PurchaseInvoiceLine(); // Create a purchase order key to specify the purchase order purchaseOrderKey = new PurchaseTransactionKey(); purchaseOrderKey.Id = "PO0997"; // Add the purchase order key to the purchase invoice line purchaseInvoiceLine.PurchaseOrderKey = purchaseOrderKey; // Set the vendor item number property for the purchase invoice line purchaseInvoiceLine.VendorItemNumber = "ATT-53BK"; // Create a quantity object to specify the quantity of an item purchaseInvoiceQuantity = new Quantity(); purchaseInvoiceQuantity.Value = 1; // Populate the quantity property of the purchase invoice line object purchaseInvoiceLine.QuantityInvoiced = purchaseInvoiceQuantity; // Create an array to hold the purchase line object PurchaseInvoiceLine[] lines = { purchaseInvoiceLine }; // Add the array of purchase invoice lines to the purchase invoice object purchaseInvoice.Lines = lines; // Get the create policy for purchase invoices purchaseInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation( "CreatePurchaseInvoice", context); // Create the purchase invoice wsDynamicsGP.CreatePurchaseInvoice(purchaseInvoice, context, purchaseInvoiceCreatePolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }