Last active
December 11, 2017 20:32
-
-
Save apost0706/e3bd7f5842fa9b54f0b0a4e51958f8e3 to your computer and use it in GitHub Desktop.
Sage 100 BOI printing issue - 2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------- | |
' Sage 100 BOI script demonstrating a printing issue with Sage 100 - 2018. | |
'------------------------------------------------- | |
' To replicate: create a new Shipping data entry in Sage, do not print it and take a note of the invoice number. | |
' Then enter that invoice number when prompted by this script. | |
' The issue is replicated when the following error message shows up: | |
'------------------------------------------------- | |
' Unable to print SO_Invoice1.rpt. | |
' Unable to cast COM object of type 'CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass' | |
' to interface type 'CrystalDecisions.ReportAppServer.Controllers.ISCRReportSource'. | |
' This operation failed because the QueryInterface call on the COM component for the interface with IID | |
' '{98CDE168-C1BF-4179-BE4C-F2CFA7CB8398}' failed due to the following error: No such interface supported | |
' (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). - ErrorNum = CI_Report_Unable | |
'------------------------------------------------- | |
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 | |
Function replace_npchars(s) | |
smsg = "" | |
for i=1 to Len(msg) | |
code=Asc(Mid(msg, i, 1)) | |
if (code < 32 or code > 160) then | |
smsg = smsg & "#" & code | |
else | |
smsg = smsg & Mid(msg, i, 1) | |
end if | |
next | |
replace_npchars = smsg | |
end function | |
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 | |
MsgBox("PathHome: " & PathHome) | |
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", "", "alex")) | |
Password = Trim(InputBox("Enter Password", "", "")) | |
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 | |
str = Trim(InputBox("Enter Invoice Number","Invoice Number", "0100069")) | |
oSEC = oSS.nSetProgram(oSS.nLookupTask("SO_Shipping_UI")) | |
Set oSEC_Shipping = oSS.oSecurity | |
Set s = oScript.NewObject("SO_Shipping_Bus", oSS) | |
sInvoiceNumber = str | |
if (str <> "") then | |
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 | |
'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)) | |
retVal = oPrint.nSelectReportSetting( sFormCode ) | |
errchk retVal, "Select Report Setting", oSS, oPrint | |
sCompanyKey = oSS.sCompanyKey | |
retVal = oPRINT.nSetKeyValue( "ModuleCode$", "S/O" ) | |
retVal = oPRINT.nSetKeyValue("CompanyKey$", sCompanyKey) | |
retVal = oPRINT.nSetKeyValue( "ReportID$", "SO_INVOICEPRINTING_UI" ) | |
RetVal = oPRINT.nSetKeyValue( "ReportSetting$", sFormCode ) | |
RetVal = oPRINT.nSetKeyValue( "RowKey$", "1" ) | |
RetVal = oPRINT.nSetKey | |
errchk retVal, "SetKey - select report", oSS, oPrint | |
'retval = oPrint.nSetPartialRecord("Plain", oScript.Evaluate("CPL(""IOLIST TemplateDesc$"")") ) | |
retval = oPrint.nSetPartialRecord(sFormCode, oScript.Evaluate("CPL(""IOLIST TemplateDesc$"")") ) | |
errchk retVal, "SetPartialRecord", 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 | |
'Write report setting to memory | |
RetVal = oPRINT.nWrite | |
errchk retVal, "Write settings", oSS, oPrint | |
RetVal = oPRINT.nProcessReport( "PRINT" ) | |
If retVAL = 0 Then | |
msg = oPrint.sLastErrorMsg | |
MsgBox("nProcessReport error: " & msg & " - ErrorNum = " & oPrint.sLastErrorNum) | |
Else | |
MsgBox("nProcessReport Success") | |
end if | |
on error resume next | |
oSS.nCleanUp () | |
if (Err.Number <> 0) then | |
MsgBox("Warning: Exception while oSS.nCleanUp call, ignoring and continuing: " & Err.Description) | |
end if | |
oSS.DropObject() | |
Set oSS = Nothing | |
Set oScript = Nothing | |
MsgBox("Completion") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment