We are on Sage 100 Advanced v2017 and I have a VBScript that prints Sales Orders using the SO_SalesOrderPrinting_UI object.
Does anyone know if this object requires an active Windows session in order to run?
The script runs perfectly when I run it manually. It also runs correctly when I schedule it with Task Schedule to "run only when user is logged on". However, we want to schedule this to run when I'm not logged on, and that doesn't work. Our IT has narrowed down to the script, because we can get other VBScript files to run correctly with this setting, such as a script that creates another file.
I've scheduled VBScripts to run that create Sales Orders from files etc, but I've never tried this printing object on the scheduler. So I'm wondering if this is the issue - after all, it does have UI right in its name.
If this is not going to run without a Windows session, does anyone have a solution for printing Sales Orders on a schedule?
(Background: some sales orders require 2 different forms to be printed, and the CSR forgets. So we have a script on SO entry that checks the SO lines for the criteria that tells us it needs to be printed, and then writes the SO number to a UDT. The scheduled script is to pick up the SO's from the UDT and print them.)
Along the lines of what Kevin said, where is the print output going to - a printer, to Paperless, to Deferred? Since there presumably could be normal UI that appears with form printing, these things come to mind IF they are relevant for you:oSS.nTerminateUI() 'an oldie so not sure if it's still supported or has been deprecated.Also obviously suppress any explicit MessageBox's, ProgressBar's, other UI you are issuing yourself.
If printing to Paperless:If oReport.PDFEnabled Then oReport.PDFSilent = 1 'Assuming oReport points to SO_SalesOrderPrinting_Rpt (NOT SO_SalesOrderPrinting_UI)
Here is my whole script, with the nTerminateUI() function added. (It did not fix the issue.) FYI - there is a loop in here that reads the SO# from a custom table, so this is more than just the printing code:
'Set values for MAS connectionServerPath = "E:\SAGE\2017 Sage 100 Advanced\MAS90\Home"UserName = "Scripts"Password = "12345678" Company = "TST"dDate = Date()ModuleDate = CStr(Year(dDate)) & Right("0" & CStr(Month(dDate)),2) & Right("0" & CStr(Day(dDate)),2)
Set oScript = CreateObject("ProvideX.Script") oScript.Init(ServerPath) Dim oSession 'As Object Set oSession = oScript.NewObject("SY_SESSION") retVal = oSession.nSetUser(UserName, Password) retVal = oSession.nSetCompany(Company) retVal = oSession.nSetDate("C/M", ModuleDate) retVal = oSession.nSetModule("C/M") retVal = oSession.nSetProgram(oSession.nLookupTask("CM_UDTMaint_UI")) Set soTable = oScript.NewObject("CM_UDTMaint_Bus", oSession, "SO_UDT_WT_PRINTING")
retVAL = soTable.nMoveFirst()
Do While Not CBool(soTable.nEOF)delete = trueretVal = oSession.nSetProgram(oSession.nLookupTask("SO_SalesOrderPrinting_UI"))
Set soPRINT = oScript.NewObject("SO_SalesOrderPrinting_rpt", oSession)oSession.nTerminateUI()retVal = soPRINT.nSetKeyValue("ModuleCode$", "S/O")retVal = soPRINT.nSetKeyValue("ReportID$", "SO_SalesOrderPrinting_UI")
retval = soTable.nGetValue("UDF_SONUMBER$",soNo)
retVal = soPRINT.nSelectReportSetting("WORK TICKET CS")
soPRINT.sQuickPrint = soNo
soPRINT.nReportType = 6retval = soPRINT.nInitReportEngine()retVal = soPRINT.nSetExportOptions(5,"\\bci-fs02\MAS\" + soNo + ".pdf")
retVal = soPRINT.nProcessReport("EXPORT")if retVal = 0 then err = soPRINT.sLastErrorMsg + "on Export; " retval = soTable.SetValue("UDF_PRINTER$", err)end if
retVal = soPRINT.nProcessReport("PRINT")if retVal = 0 then err = err + soPRINT.sLastErrorMsg + "on Print; " retval = soTable.SetValue("UDF_PRINTER$", err) delete = falseelseSet oSO = oScript.NewObject("SO_SalesOrder_bus",oSession)retVal = oSO.AsObject(oSO.ScriptObject).DeactivateProcedure("PostWrite") retVal = oSO.nSetKeyValue("SalesOrderNo$",soNo)retVal = oSO.nSetKey()retVal = oSO.nSetValue("UDF_WORK_TICKET_PRINTED$","Y")retVal = oSO.nWrite()If retVal = 0 and delete then err = err + soSO.sLastErrorMsg + "on SO Save" retval = soTable.SetValue("UDF_PRINTER$", err)End ifSet oSO = nothingSet soPRINT = nothing
If delete thensoTable.nDelete()End if
I see you are already setting the QuickPrint property to the SO number on the _RPT object (via soPRINT) so that's good. Also you have nReportType = 6 for the UI suppress on export so that's good too.
Is the WORK TICKET CS form Paperless enabled or does the nProcessReport("PRINT") go to an actual printer? If actual printer that printer name for that WORK TICKET CS form code has to be valid for the Windows user specified inside the Windows Task Scheduler job when it's running unattended. I noted a way below to hard code the printer name if that's applicable for you.If Paperless enabled you can add: If soPRINT.PDFEnabled Then soPRINT.PDFSilent = 1
Also I noticed for soPRINT you are doing only 2 nSetKeyValue's and the accompanying nSetKey, nSetValue, and nWrite are missing. Note: I haven't tested this so this may not be 100% right but this is how I would initially approach it:
repSetting = "WORK TICKET CS"
retVal = soPRINT.nSelectReportSetting(repSetting)
retVal = soPRINT.nSetKeyValue("ModuleCode$", "S/O")retVal = soPRINT.nSetKeyValue("CompanyKey$", oSession.sCompanyKey)retVal = soPRINT.nSetKeyValue("ReportID$", "SO_SalesOrderPrinting_ui")retVal = soPRINT.nSetKeyValue("ReportSetting$", repSetting) retVal = soPRINT.nSetKeyValue("RowKey$", "00001")retVal = soPRINT.nSetKey()
retVal = soPRINT.nSetValue("SelectField$", "Order Number")retVal = soPRINT.nSetValue("SelectFieldValue$", "Order Number")retVal = soPRINT.nSetValue("Tag$", "TABLE=SO_SALESORDERHEADER; COLUMN=SALESORDERNO$;")retVal = soPRINT.nSetValue("Operand$", "=")retVal = soPRINT.nSetValue("Value1$", soNo)retVal = soPRINT.nSetValue("KeyReference$", "")
soPRINT.sQuickPrint = soNoIf soPRINT.PDFEnabled Then soPRINT.PDFSilent = 1
retVal = soPRINT.nWrite()
'optional line to hard code a printer prior to the nProcessReport("PRINT")'retVal = soPRINT.nValidatePrinter("enter printer name") ' e.g. retVal = soPRINT.ValidatePrinter("HP LaserJet 5") 'now check the retVal