Cannot Create Business Object

SOLVED

I am using the docs and examples from the Sage University BOI class. I cannot get past a certain point. The user has full access rights.

This line returns a number "20000001"

Dim TaskID As Integer = oSS.nLookupTask("GL_Account_ui")

This line returns a number "100004" instead of the expected 1 or 0

retVAL = oSS.nSetProgram(TaskID)

Then of course this line fails

oGLAccount = oScript.NewObject("GL_Account_bus", oSS)

Complete Code Below:

    Public Sub CreateConnectionDemo()


        oScript = CreateObject("ProvideX.Script")
        oScript.Init("M:\Best\Mas 200\Version4\Mas90\Home")
        oSS = oScript.NewObject("SY_Session")

        retVAL = oSS.nlogon()

        If retVAL = 0 Then
            User = Trim(InputBox("Enter User Name"))
            Password = Trim(InputBox("Enter Password"))
            retVAL = oSS.nSetUser(User, Password)
        End If

        If retVAL = 0 Then
            MsgBox(oSS.sLastErrorMsg)
            oSS.DropObject()
            oSS = Nothing
            oSS.WScript.Quit()
        End If

        retVAL = oSS.nSetCompany("TST")

        If retVAL = 0 Then
            MsgBox(oSS.sLastErrorMsg)
            oSS.DropObject()
            oSS = Nothing
            oSS.WScript.Quit()
        End If

        retVAL = oSS.nSetDate("G/L", "20050315")

        If retVAL = 0 Then
            MsgBox("SetDate Failed - " & oSS.sLastErrorMsg)
        Else

            retVAL = oSS.nSetModule("G/L")

            If retVAL = 0 Then
                MsgBox("SetModule Failed - " & oSS.sLastErrorMsg)
            Else
                MsgBox("Current Company: " & oSS.sCompanyName & vbCrLf & "Company Data Path: " & oSS.sPathCompany & vbCrLf & "Current Module: " & oSS.sModuleName & vbCrLf & "Module Date: " & oSS.sModuleDate)
            End If
        End If

        Dim TaskID As Integer = oSS.nLookupTask("GL_Account_ui")

        retVAL = oSS.nSetProgram(TaskID)

        If retVAL = 0 Then
            oGLAccount = oScript.NewObject("GL_Account_bus", oSS)
        Else
            Dim mssg = oSS.sLastErrorMsg
            MsgBox(mssg)
        End If

        MsgBox("Read Access:" & CStr(oSS.oSecurity.nReadAccess) & vbCrLf & "Create Access:" & CStr(oSS.oSecurity.nCreateAccess) & vbCrLf & "Modify Access:" & CStr(oSS.oSecurity.nModifyAccess) & vbCrLf & "Delete Access:" & CStr(oSS.oSecurity.nDeleteAccess))

        If oSS.oSecurity.nCreateAccess = 1 Then
            MsgBox("User Has Create Privilages")
        Else
            MsgBox("User Does Not Have Create Privilages")
        End If

        oSS.nCleanUp()
        oSS.DropObject()
        oSS = Nothing
        oScript = Nothing

    End Sub

Parents
  • 0

    Thank you to Kent Mackall For finding the Answer. His answer was deleted by the SageCity spam filter.

           If retVAL = 0 Then <==== Problem is Here. Docs are wrong. Example 3 Lab is not correct. Change to ">" or "<>"

               oGLAccount = oScript.NewObject("GL_Account_bus", oSS)

           Else

               Dim mssg = oSS.sLastErrorMsg

               MsgBox(mssg)

           End If

  • 0 in reply to John1966

    Oops,  I will see if I can get that document corrected.  Thanks!

    Kent

  • 0 in reply to Kent Mackall

    Kent, Trying to get your post put back up so i can mark it as the answer.

  • 0 in reply to Kent Mackall
    verified answer

    Here is the original reply in full:

    Greetings,

    The SetProgram method returns zero on failure or a handle to a Security Object on success. The object handle is always greater than 1.  It looks like the LookupTask and SetProgram are succeeding.

    Looking at your full code, you have this conditional statement:

          If retVAL = 0 Then

              oGLAccount = oScript.NewObject("GL_Account_bus", oSS)

          Else

              Dim mssg = oSS.sLastErrorMsg

              MsgBox(mssg)

          End If

    Since retVAL will only be zero on failure, the Account object will only be instantiated if the SetProgram failed and returned zero.  Try changing this logic to test for success by doing something like:

          If retVAL > 0 Then

              oGLAccount = oScript.NewObject("GL_Account_bus", oSS)

          Else

              Dim mssg = oSS.sLastErrorMsg

              MsgBox(mssg)

          End If

    If you have already done this and are still having problems, then please post back with details about any error information that is being returned when the NewObject fails.

    Thanks,

    Kent

Reply
  • 0 in reply to Kent Mackall
    verified answer

    Here is the original reply in full:

    Greetings,

    The SetProgram method returns zero on failure or a handle to a Security Object on success. The object handle is always greater than 1.  It looks like the LookupTask and SetProgram are succeeding.

    Looking at your full code, you have this conditional statement:

          If retVAL = 0 Then

              oGLAccount = oScript.NewObject("GL_Account_bus", oSS)

          Else

              Dim mssg = oSS.sLastErrorMsg

              MsgBox(mssg)

          End If

    Since retVAL will only be zero on failure, the Account object will only be instantiated if the SetProgram failed and returned zero.  Try changing this logic to test for success by doing something like:

          If retVAL > 0 Then

              oGLAccount = oScript.NewObject("GL_Account_bus", oSS)

          Else

              Dim mssg = oSS.sLastErrorMsg

              MsgBox(mssg)

          End If

    If you have already done this and are still having problems, then please post back with details about any error information that is being returned when the NewObject fails.

    Thanks,

    Kent

Children
No Data