Imports WebServicesGP2010.ServiceReference1
Imports System.ServiceModel
Public Class CreatePurchaseInvoice
Sub shipmentInvoice()
Dim companyKey As CompanyKey
Dim context As Context
Dim VendorKey As VendorKey
Dim purchaseInvoiceKey As PurchaseTransactionKey
Dim purchaseOrderKey As PurchaseTransactionKey
Dim purchaseInvoice As PurchaseInvoice
Dim purchaseInvoiceLine As PurchaseInvoiceLine
Dim itemKey As ItemKey
Dim purchaseInvoiceQuantity 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)
' Populate the required properties for the purchase receipt object
purchaseInvoice = New PurchaseInvoice
purchaseInvoice.VendorDocumentNumber = "vndDocNum003"
' Create a purchase transaction key to identify the purchase receipt
purchaseInvoiceKey = New PurchaseTransactionKey()
purchaseInvoiceKey.Id = "RCT4075"
purchaseInvoice.Key = purchaseInvoiceKey
' Create a vendor key object to specify the vendor for the purchase receipt
VendorKey = New VendorKey()
VendorKey.Id = "TELESATE0006"
purchaseInvoice.VendorKey = VendorKey
' Create a purchase receipt line object for the purchase receipt object
purchaseInvoiceLine = New PurchaseInvoiceLine
' Create an item key object to specify the item
' Populate the item key property of the purchase receipt line object
itemKey = New ItemKey
itemKey.Id = "PAINT"
purchaseInvoiceLine.ItemKey = itemKey
purchaseOrderKey = New PurchaseTransactionKey
purchaseOrderKey.Id = "PO2076"
purchaseInvoiceLine.PurchaseOrderKey = purchaseOrderKey
' Populate the vendor item number property of the purchase receipt line
purchaseInvoiceLine.VendorItemNumber = "PAINT"
' Create a quantity object to specify the quantity
' Populate the shipped quantity property of the purchase receipt line
purchaseInvoiceQuantity = New Quantity
purchaseInvoiceQuantity.Value = 1
purchaseInvoiceLine.QuantityInvoiced = purchaseInvoiceQuantity
' Create an array to hold the purchase receipt line
Dim lines(0) As PurchaseInvoiceLine
lines(0) = purchaseInvoiceLine
' Add the array of purchase receipt lines to the purchase receipt object
purchaseInvoice.Lines = lines
' Get the create policy for purchase receipt objects
purchaseReceiptCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePurchaseInvoice", context)
' Create the purchase invoice
Try
wsDynamicsGP.CreatePurchaseInvoice(purchaseInvoice, context, purchaseReceiptCreatePolicy)
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