BOI Session is broken after Invoice print

SOLVED

Hello Forum,

Is anybody also seeing this problem with Sage 100 Premium ERP 2013 (Version 5.00.5.0)?

An invoice is created (or modified) successfully and the Invoice form is printed, after which the session object becomes corrupted and it is impossible to use it anymore.

Our customers have to restart the software after they print an invoice so that the session is recreated.

I am posting a script replicating the problem below, it has the spots marked where BOI calls fail.

Any advice would be very much appreciated.

Thanks,

Alex
V-Technologies

Sub errchk(r, desc, oss, o)
    if (r = 0) then
        MsgBox(desc & ": " & o.sLastErrorMsg)
        oss.nCleanup()
        oss.DropObject()
        Set oss = Nothing
        WScript.Quit
    end if
end sub

Const HKEY_CURRENT_USER = &H80000001
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
RetVal = oReg.GetExpandedStringValue(HKEY_CURRENT_USER,"Software\Sage Software\MAS 90 Business Desktop\Settings", _
        "MAS90RootDirectory",PathRoot)  
if retVal <> 0 then
  oReg.GetExpandedStringValue HKEY_CURRENT_USER,"Software\ODBC\ODBC.INI\SOTAMAS90","Directory",PathRoot
end if  

PathHome = PathRoot & "\Home"
Set oReg = Nothing

Set oScript = CreateObject ("ProvideX.Script")

    'oScript.TraceOn=true

oScript.Init(Pathhome)
Set oSS = oScript.NewObject("SY_Session")
retVAL = oSS.nLogon()
If retVAL = 0 Then
  User = Trim(InputBox("Enter User Name", "", "ap"))
  Password = Trim(InputBox("Enter Password", "", "ap"))
  retVAL = oSS.nSetUser(User,Password)
  errchk retVal, "SetUser", oss, oScript
End If

sCompany = oSS.sCompanyCode
sCompany = Trim(InputBox("Enter Company Code","Company Code",sCompany))
retVAL = oSS.nSetCompany(sCompany)
errchk retVal, "SetCompany", oSS, oSS

sDate = oSS.sModuleDate
if sDate = "" then
  sDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2)      
end if  
retVAL = oSS.nSetDate("S/O",sDate)
errchk retVal, "SetDate", oSS, oSS

retVal = oSS.nSetModule("S/O")
errchk retVal, "Set Module", oSS, oSS

sDocumentKey = Trim(InputBox("Enter Sales Order Number","SalesOrder Number", "TEST"))
oSEC = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_UI"))
Set o = oScript.NewObject("SO_SalesOrder_bus", oSS)
r = o.nFind(sDocumentKey)
errchk r, "SalesOrder find", oSS, o

oSEC = oSS.nSetProgram(oSS.nLookupTask("SO_Shipping_UI"))
Set s = oScript.NewObject("SO_Shipping_Bus", oSS)

fld = "CurrentInvoiceNo$"
str = ""
r = o.nGetValue(fld, str)
errchk r, "GetValue CurrentInvoice Error", oSS, o
sInvoiceNumber = str

if (str <> "") then
    MsgBox("Invoice found: " & sInvoiceNumber)

    r = s.nFind(sInvoiceNumber)
    errchk r, "Invoice Number Find failed", oSS, s
    
    r = s.nSetKey(sInvoiceNumber)
    errchk r, "Invoice Number SetKey failed", oSS, s
else
    r = s.nGetNextInvoiceNo(sInvoiceNumber)
    errchk r, "GetNextInvoiceNumber failed", oSS, s
    
    MsgBox("New Invoice Number " & sInvoiceNumber)
end if

r = s.nSetKey(sInvoiceNumber)
errchk r, "Setting Key on invoice number", oSS, s

r = s.nSetValue("SALESORDERNO$", sDocumentKey)
errchk r, "Setting SalesOrderNumber for the invoice", oSS, s

s.oLines.nMoveFirst
do while (s.oLines.nEOF = 0)
    sLineKey = ""
    s.oLines.nGetValue "LINEKEY$", sLineKey
    iQuantityOrdered = 0
    s.oLines.nGetValue "QUANTITYORDERED", iQuantityOrdered
    s.oLines.nSetValue "QUANTITYSHIPPED", iQuantityOrdered
    
    s.oLines.nMoveNext
loop

r = s.oLines.nWrite
errchk r, "Writing lines", oSS, s

r = s.nSetValue("PrintInvoice$", "Y")
errchk r, "Setting PrintInvoice field", oSS, s

r = s.nWrite
errchk r, "Invoice Write", oSS, s

o.nFind("")

'retVAL = oSS.nSetProgram(oSS.nLookupTask("SO_PACKINGLISTPRINTING_UI"))
retVAL = oSS.nSetProgram(oSS.nLookupTask("SO_INVOICEPRINTING_UI"))
errchk retVal, "SetProgram", oSS, oSS

'Set oPrint = oScript.NewObject("SO_PACKINGLISTPRINTING_RPT",oSS)
Set oPrint = oScript.NewObject("SO_INVOICEPRINTING_RPT",oSS)

oSS.nTerminateUI

sFormCode = "STANDARD"
sFormCode = Trim(InputBox("Enter Form Code",,sFormCode))

'sQuickPrint = Trim(InputBox("Try quick print (Y/N)?","","Y"))

' the following can be used to replace the setvalue, write below, but takes longer
'if sQuickPrint = "Y" then
'  RetVAl = oPRINT.sQuickPrint = sDocumentKey
'  RetVal = oPRINT.nProcessReport( "PREVIEW" )  
'  If retVAL = 0 Then
'    MsgBox("QuickPrint - nProcessReport Failed - " & oPrint.sLastErrorMsg & " - ErrorNum = " & oPrint.sLastErrorNum)
'  Else
'    MsgBox("QuickPrint - nProcessReport Success")
'  end if
'end if

retVal = oPrint.nSelectReportSetting( sFormCode )
errchk retVal, "Select Report Setting", oSS, oPrint
      
RetVal = oPRINT.nSetKeyValue( "ReportSetting$", sFormCode )
RetVal = oPRINT.nSetKeyValue( "RowKey$", "1" )
RetVal = oPRINT.nSetKey
errchk retVal, "SetKey", oSS, oPrint

' Set Selection criteria
RetVal = oPRINT.nSetValue( "SelectField$", "Invoice Number" )
errchk retVal, "SetValue - SelectField", oSS, oPrint
RetVal = oPRINT.nSetValue( "SelectFieldValue$", "Invoice Number" )
errchk retVal, "SetValue - SelectFieldValue", oSS, oPrint
RetVal = oPRINT.nSetValue( "Tag$", "TABLE=SO_INVOICEHEADER; COLUMN=INVOICENO$" )
errchk retVal, "SetValue - Table", oSS, oPrint
RetVal = oPRINT.nSetValue( "Operand$", "=" )
errchk retVal, "SetValue - Operand", oSS, oPrint
RetVal = oPRINT.nSetValue( "Value1$", sInvoiceNumber )
errchk retVal, "SetValue - Value1", oSS, oPrint
MsgBox(sInvoiceNumber)

'Write report setting to memory
RetVal = oPRINT.nWrite
errchk retVal, "Write", oSS, oPrint
 
RetVal = oPRINT.nProcessReport( "PRINT" )
If retVAL = 0 Then
    MsgBox("nProcessReport warning - " & oPrint.sLastErrorMsg & " - ErrorNum = " & oPrint.sLastErrorNum)
    ''''''''''''''''''''''''''
    ' Point of failure
    '---------------------------
    '---------------------------
    'nProcessReport warning - The S/O0000000001SO_INVOICEPRINTING_UI
    '---------------------------
    'OK   
    '---------------------------
Else
    MsgBox("nProcessReport Success")
end if



oSEC = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_UI"))
''''''''''''''''''''''''''
' Point of failure
'---------------------------
'Windows Script Host
'---------------------------
'Script:    C:\src\StarShip Client\Current Version\MAS\TestScripts\printInvoice.vbs
'Line:    176
'Char:    1
'Error:    <Error: 0 in Method LOOKUPTASK>
'Code:    80020009
'Source:     ProvideX Library

'---------------------------
'OK   
'---------------------------

Set o = oScript.NewObject("SO_SalesOrder_bus", oSS)
r = o.nFind(sDocumentKey)
errchk r, "SalesOrder find", oSS, o

on error resume next
oSS.nCleanUp ()
if (Err.Number <> 0) then
    MsgBox("Warning: Exception while oSS.nCleanUp call, ignoring and continuing: " & Err.Description)
    ' Point of failure
    '---------------------------
    'Windows Script Host
    '---------------------------
    'Script:    C:\src\StarShip Client\Current Version\MAS\TestScripts\printInvoice.vbs
    'Line:    166
    'Char:    1
    'Error:    <Error: 0 in Method CLEANUP>
    'Code:    80020009
    'Source:     ProvideX Library
    '---------------------------
    'OK   
    '---------------------------
end if

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

MsgBox("Success")

  • 0

    Greetings,

    Is this the line that causes the first failure:

    RetVal = oPRINT.nProcessReport( "PRINT" )

    If so, what is the full text returned in oPrint.sLastErrorMsg?

    If that line succeeds and the failure is at:

    oSEC = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_UI"))

    Then what is the value of oSS right before that call?  Also, what is the initial value of oSS after it is set the first time?

    Finally, this may be related to an issue where the security object is being assigned to a different object during processing but I am not sure from the post. If that is the case, then you can try saving off the value of oSEC from when it is initially set at the beggining of the script and then reuse that same value after the print.

    Thanks,

    Kent

  • 0 in reply to Kent Mackall

    Hello Kent,

    nProcessReport call fails. Then any call like nLookupTask, oSS.nCleanUp - fails.

    You mentioned oSS value; is it one of its properties? Please advise; I can only check if it is null of not, since it is an object. It is not null everywhere after its initial assignment.

    oSS is no problem to use anywhere before the nProcessReport call.

    if I call nLookupTask before printing, even more than one time, with the same  oSS as initially assigned, it succeeds.

    It is after nProcessReport that it fails.

    How can I reuse the security object for a session - please advise, this might be a solution.

    I tried assigning it to Session / Security but it is read only.

    I thought about closing/reopening the session, but even oSS.nCleanUp fails; would need a cleaner solution.

    Regarding the LastErrorMessage after nProcessReport - there are zero symbols in there, that is why the rest of the string is not shown in my scripts above. The full message looks like this (#0 represents Chr(0)):

    "S/O0000000001SO_INVOICEPRINTING_UI#0#0#0#0#0#0#0#0#0STANDARD#0#0#0#0#0#0#0#0#0#0#0#000001 is invalid."

    nProcessReport returns 0,sLastErrorNum = CI_NoKey.

    nLookupTask call also fails - it does not return anything, script generates exception with message Error:                <Error: 0 in Method LOOKUPTASK>.

    Thanks,

    Alex

  • 0 in reply to postnik706

    Greetings,

    That information helps.  The error is indicating an issue with the key and it looks like the key for the SY_ReportSelection.M4T table.  What records if any are in this table for the SO_Invoice_UI?  What happens if you delete the records (make a backup of the file first) related to SO_Invoice_UI from this table and try running your script again?

    If that doesn't help, please open a support case with Customer Support so that this issue can be appropriately handled.

    Thanks,

    Kent

  • 0 in reply to Kent Mackall

    That table is always empty.

    I looked at the SQL traces and initiated Invoice Printing in MAS UI. There are only Selects from that table.

    I renamed the table to check if I'm looking at the right database and got an error in MAS as expected.

    Thanks,

    Alex

  • 0 in reply to postnik706

    Kent,

    I reported it on the Partner Portal but they seem to support only Sage 50 over there.

    Could you please point out a proper resource where I could post this question?

    Thanks,

    Alex

  • 0 in reply to postnik706

    Here is a link to the Sage 100 ERP Support website: support.na.sage.com/.../msbrowse.do

  • 0 in reply to Kent Mackall
    verified answer

    Thanks, I tried that but it only allows posting Sage 50 issues (due to our Partner account limitation - not sure about that).

    We will phone Support.

    Thanks for your help.

  • 0 in reply to postnik706

    This is a very old post but I'm coming across a similar issue with Sage 100 2016 Premium.  Just curious to see if/how you resolved this?