stanley1271 6/2/2009 3:43:06 PM

Vendor Lookup Exceptions

I have some code (see below) where I am trying to see if a vendor exists. However, in the case where the vendor does not exist I get an exception thrown from the webservice. If the vendor is there then all is good. So besides traping the error and assuming (this would be bad) that the issue was the vendor did not exist, is there some other way to check to see if they exist? I really don't want to pull back *all* vendors just to loop through them as this could get memory intensive.

[code]

    Private Function GetVendorByKey(ByVal AgentID As String, ByVal CompanyId As Integer) As Vendor
        Dim companyKey As New CompanyKey
        Dim context As New Context
        Dim vendor As New Vendor
        Dim vendorKey As New VendorKey
        Dim gpWS As New DynamicsGP
        Try
            gpWS.UseDefaultCredentials = True
            gpWS.Credentials = System.Net.CredentialCache.DefaultCredentials
            gpWS.Timeout = System.Threading.Timeout.Infinite

            companyKey.Id = CompanyId

            context.OrganizationKey = DirectCast(companyKey, OrganizationKey)
            context.CultureName = "en-US"

            vendorKey.Id = AgentID
            vendor = gpWS.GetVendorByKey(vendorKey, context)
        Catch ex As Exception
            GP.SharedMethods.Errors.ReportException(ex, "There was a problem finding then agent " & AgentID & " .", True)
            vendor = Nothing
        Finally
            'Clean up
            companyKey = Nothing
            context = Nothing
            vendor = Nothing
            vendorKey = Nothing
            gpWS.Dispose()
            gpWS = Nothing
        End Try

        Return vendor
    End Function

[/code]

Version: Unknown or N/A
Section: Visual Studio Tools for Dynamics GP


Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3