This method creates a new purchase order document.
Parameter |
Type |
Description |
---|---|---|
purchaseOrder |
The purchase order 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 order document with the key “PO4055”. The example demonstrates setting the purchase order document’s required key and vendor key properties. The example uses a single purchase order line to specify warehouse, 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 purchaseOrderKey; VendorKey vendorKey; PurchaseOrder purchaseOrder; PurchaseOrderLine purchaseOrderLine; WarehouseKey warehouseKey; Quantity quantityOrdered; Policy purchaseOrderCreatePolicy; // 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 order purchaseOrderKey = new PurchaseTransactionKey(); purchaseOrderKey.Id = "PO4055"; // Create a vendor key object to specify the vendor vendorKey = new VendorKey(); vendorKey.Id = "ACETRAVE0001"; // Create a purchase order object purchaseOrder = new PurchaseOrder(); // Populate the required properties purchaseOrder.Key = purchaseOrderKey; purchaseOrder.VendorKey = vendorKey; // Create a purchase order line object for the purchase order object purchaseOrderLine = new PurchaseOrderLine(); // Create a warehouse key to specify the warehouse warehouseKey = new WarehouseKey(); warehouseKey.Id = "WAREHOUSE"; // Add the warehouse key to the purchase order line object purchaseOrderLine.WarehouseKey = warehouseKey; // Create a quantity object to specify the quantity ordered quantityOrdered = new Quantity(); quantityOrdered.Value = 10; // Add the quantity to the purchase order line object purchaseOrderLine.QuantityOrdered = quantityOrdered; // Specify the inventory item being purchased purchaseOrderLine.VendorItemNumber = "100XLG"; // Create an array to hold the purchase order line object PurchaseOrderLine[] lines = { purchaseOrderLine }; // Add the array of purchase order lines to the purchase order object purchaseOrder.Lines = lines; // Get the create policy for purchase order objects purchaseOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePurchaseOrder", context); // Create the purchase order wsDynamicsGP.CreatePurchaseOrder(purchaseOrder, context, purchaseOrderCreatePolicy); } } }
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 purchaseOrderKey; VendorKey vendorKey; PurchaseOrder purchaseOrder; PurchaseOrderLine purchaseOrderLine; WarehouseKey warehouseKey; Quantity quantityOrdered; Policy purchaseOrderCreatePolicy; // 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 order purchaseOrderKey = new PurchaseTransactionKey(); purchaseOrderKey.Id = "PO4055"; // Create a vendor key object to specify the vendor vendorKey = new VendorKey(); vendorKey.Id = "ACETRAVE0001"; // Create a purchase order object purchaseOrder = new PurchaseOrder(); // Populate the required properties purchaseOrder.Key = purchaseOrderKey; purchaseOrder.VendorKey = vendorKey; // Create a purchase order line object for the purchase order object purchaseOrderLine = new PurchaseOrderLine(); // Create a warehouse key to specify the warehouse warehouseKey = new WarehouseKey(); warehouseKey.Id = "WAREHOUSE"; // Add the warehouse key to the purchase order line object purchaseOrderLine.WarehouseKey = warehouseKey; // Create a quantity object to specify the quantity ordered quantityOrdered = new Quantity(); quantityOrdered.Value = 10; // Add the quantity to the purchase order line object purchaseOrderLine.QuantityOrdered = quantityOrdered; // Specify the inventory item being purchased purchaseOrderLine.VendorItemNumber = "100XLG"; // Create an array to hold the purchase order line object PurchaseOrderLine[] lines = { purchaseOrderLine }; // Add the array of purchase order lines to the purchase order object purchaseOrder.Lines = lines; // Get the create policy for purchase order objects purchaseOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePurchaseOrder", context); // Create the purchase order wsDynamicsGP.CreatePurchaseOrder(purchaseOrder, context, purchaseOrderCreatePolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }