Imports WebServicesGP2010.ServiceReference1
Imports System.ServiceModel
Public Class CreatePurchaseReceipt
Sub shipment()
Dim companyKey As CompanyKey
Dim context As Context
Dim VendorKey As VendorKey
Dim WarehouseKey As WarehouseKey
Dim purchaseReceiptKey As PurchaseTransactionKey
Dim purchaseReceipt As PurchaseReceipt
Dim purchaseReceiptLine As PurchaseReceiptLine
Dim itemKey As ItemKey
Dim purchaseReceiptQuantity As Quantity
Dim purchaseReceiptCreatePolicy 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 receipt
purchaseReceiptKey = New PurchaseTransactionKey()
'purchaseReceiptKey.Id = "RCT4075"
' Create a vendor key object to specify the vendor for the purchase receipt
VendorKey = New VendorKey()
VendorKey.Id = "TELESATE0006"
' Create a purchase receipt object
purchaseReceipt = New PurchaseReceipt
' Populate the required properties for the purchase receipt object
purchaseReceipt.Key = purchaseReceiptKey
purchaseReceipt.VendorKey = VendorKey
' Create a purchase receipt line object for the purchase receipt object
purchaseReceiptLine = New PurchaseReceiptLine
' Create an item key object to specify the item
itemKey = New ItemKey
itemKey.Id = "PAINT"
' Populate the item key property of the purchase receipt line object
purchaseReceiptLine.ItemKey = itemKey
Dim purchaseTransactionKey As New PurchaseTransactionKey
purchaseTransactionKey.Id = "PO2076"
purchaseReceiptLine.PurchaseOrderKey = purchaseTransactionKey
' Populate the vendor item number property of the purchase receipt line
purchaseReceiptLine.VendorItemNumber = "PAINT"
' Create a warehouse key object to specify the warehouse
WarehouseKey = New WarehouseKey
WarehouseKey.Id = "PAINT"
' Populate the purchase receipt line's warehouse key property
purchaseReceiptLine.WarehouseKey = WarehouseKey
' Create a quantity object to specify the quantity
purchaseReceiptQuantity = New Quantity
purchaseReceiptQuantity.Value = 1
' Populate the shipped quantity property of the purchase receipt line
purchaseReceiptLine.QuantityShipped = purchaseReceiptQuantity
' Create an array to hold the purchase receipt line
Dim lines(0) As PurchaseReceiptLine
lines(0) = purchaseReceiptLine
' Add the array of purchase receipt lines to the purchase receipt object
purchaseReceipt.Lines = lines
' Get the create policy for purchase receipt objects
purchaseReceiptCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePurchaseReceipt", context)
' Create the purchase receipt
wsDynamicsGP.CreatePurchaseReceipt(purchaseReceipt, context, purchaseReceiptCreatePolicy)
' Close the service
If wsDynamicsGP.State <> CommunicationState.Faulted Then
wsDynamicsGP.Close()
End If
End Sub
End Class