'Imports System
'Imports System.Collections.Generic
'Imports System.Linq
'Imports System.Text
Imports WebServicesGP2010.ServiceReference1
Imports System.ServiceModel
Public Class CreatePurchaseOrder
Sub StandardPO()
Dim companyKey As CompanyKey
Dim context As Context
Dim purchaseOrderKey As PurchaseTransactionKey
Dim VendorKey As VendorKey
Dim PurchaseOrder As PurchaseOrder
Dim PurchaseOrderLine As PurchaseOrderLine
Dim WarehouseKey As WarehouseKey
Dim quantityOrdered As Quantity
Dim purchaseOrderCreatePolicy As Policy
' Create an instance of the service
Dim wsDynamicsGP As DynamicsGPClient = 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 = CType(companyKey, OrganizationKey)
' Create a purchase transaction key to identify the purchase order
purchaseOrderKey = New PurchaseTransactionKey
'leave the PO Number blank to auto create
'purchaseOrderKey.Id = "PO4057"
' Create a vendor key object to specify the vendor
VendorKey = New VendorKey
VendorKey.Id = "TELESATE0006"
' 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 = "PAINT"
' 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 = "PAINT"
PurchaseOrderLine.UofM = "EACH"
' Create an array to hold the purchase order line object
Dim lines(0) As PurchaseOrderLine
lines(0) = 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
Try
wsDynamicsGP.CreatePurchaseOrder(PurchaseOrder, context, purchaseOrderCreatePolicy)
Catch ex As System.ServiceModel.FaultException
Throw ex
Catch ex As Exception
Throw ex
End Try
' Close the service
If wsDynamicsGP.State <> CommunicationState.Faulted Then
wsDynamicsGP.Close()
End If
End Sub
Sub dropShipPO()
'differ from the basic Create PO,
'requires a customer key
Dim companyKey As CompanyKey
Dim context As Context
Dim purchaseOrderKey As PurchaseTransactionKey
Dim VendorKey As VendorKey
Dim PurchaseOrder As PurchaseOrder
Dim PurchaseOrderLine As PurchaseOrderLine
Dim WarehouseKey As WarehouseKey
Dim quantityOrdered As Quantity
Dim purchaseOrderCreatePolicy As Policy
Dim customerKey As CustomerKey
' Create an instance of the service
Dim wsDynamicsGP As DynamicsGPClient = 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 = CType(companyKey, OrganizationKey)
' Create a purchase transaction key to identify the purchase order
purchaseOrderKey = New PurchaseTransactionKey
'leave the PO Number blank to auto create
'purchaseOrderKey.Id = "PO4057"
' Create a vendor key object to specify the vendor
VendorKey = New VendorKey
VendorKey.Id = "TELESATE0006"
' Create a purchase order object
PurchaseOrder = New PurchaseOrder
customerKey = New CustomerKey
customerKey.Id = "AARONFIT0001"
' Populate the required properties
PurchaseOrder.Key = purchaseOrderKey
PurchaseOrder.VendorKey = VendorKey
PurchaseOrder.CustomerKey = customerKey
PurchaseOrder.Type = PurchaseOrderType.DropShip
' 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 = "PAINT"
' 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 = "PAINT"
PurchaseOrderLine.UofM = "EACH"
' Create an array to hold the purchase order line object
Dim lines(0) As PurchaseOrderLine
lines(0) = 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
Try
wsDynamicsGP.CreatePurchaseOrder(PurchaseOrder, context, purchaseOrderCreatePolicy)
Catch ex As System.ServiceModel.FaultException
Throw ex
Catch ex As Exception
Throw ex
End Try
' Close the service
If wsDynamicsGP.State <> CommunicationState.Faulted Then
wsDynamicsGP.Close()
End If
End Sub
End Class