Site Search:
Sign in | Join | Help

Vendor Lookup Exceptions

Last post 06-02-2009 4:10 PM by stanley1271. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-02-2009 3:43 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]

    Stanley

    I'm a programmer, not a DBA.

    Currently Using:      Currently Mastered:
    Microsoft GP 10       Wasting Time
    eConnect 10
    MS SQL 2k8
    Visual Studio 2k5
    VB.NET

    Twitter: @StanleyGlass
    • Post Points: 0
  • 06-02-2009 4:01 PM In reply to

    • Steve Gray
    • Top 10 Contributor
      Male
    • Joined on 01-10-2007
    • Bradenton, Florida
    • Guru
    • Points 2,296

    Re: Vendor Lookup Exceptions

    Personally, I don't use the 'Web Services'. I just write a stored procedure:

    SELECT VENDORID FROM PM00200 WHERE VENDORID = @VENDORID

    Way, way easier.

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • Post Points: 0
  • 06-02-2009 4:10 PM In reply to

    Re: Vendor Lookup Exceptions

    Oh noes, i'm blinded by SQL. lol Trying real hard not to use SQL to do this. I guess my only other option is to download the list.

    Stanley

    I'm a programmer, not a DBA.

    Currently Using:      Currently Mastered:
    Microsoft GP 10       Wasting Time
    eConnect 10
    MS SQL 2k8
    Visual Studio 2k5
    VB.NET

    Twitter: @StanleyGlass
    • Post Points: 0
Page 1 of 1 (3 items)