Sage MAS 100 ERP Premium 4.50.7.0 running on MS Windows Server 2008 R2 We are attempting to convert a script that prints a Sales Invoice to a physical printer to instead output the Invoice as an e-mail with PDF attached. For the user we have successfully created a new form code that only has been used to set Paperless Output to "Electronically Deliver Only". When running the unattended script it does not honor this setting as expected and instead prints to the Workstation default printer. Perusing this and the other Sage User forums has not yielded guidance in this particular situation so I am requesting assistance in determining what is required to enforce unattended Electronic form delivery when printing invoices. Has anyone successfully implemented this and could give us a code snip for guidance? Here is a snippet of what we currently run: Set oSS = oPVX.NewObject("SY_Session") ' Set the User for the Session Object retVal = oSS.nSetUser("********", "**********") if retVal = 0 then stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "Return code " & retVal & " from setUser call. Exiting script. " objLog.WriteLine stamp & txtline & oSS.sLastErrorMsg WScript.Quit end if ' Set the Company for the Session Object retVal = oSS.nSetCompany(Company,1) if retVal = 0 then stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "Return code " & retVal & " from setCompany call. Exiting script. " objLog.WriteLine stamp & txtline & oSS.sLastErrorMsg WScript.Quit end if ' Set Date on the Session Object retVal = oSS.nSetDate("S/O", aDate) if retVal = 0 then stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "Return code " & retVal & " from setDate call. Exiting script. " objLog.WriteLine stamp & txtline & oSS.sLastErrorMsg WScript.Quit end if ' Set the primary Module for the Session Object retVal = oSS.nSetModule("S/O") if retVal = 0 then stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "Return code " & retVal & " from setModule call. Exiting script. " objLog.WriteLine stamp & txtline & oSS.sLastErrorMsg WScript.Quit end if ' Set the UI Task for the Session Object retVal = oSS.nSetProgram(oSS.nLookupTask("SO_InvoicePrinting_ui")) if retVal = 0 then stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "Return code " & retVal & " from setProgram SO_InvoicePrinting_ui call. Exiting script. " objLog.WriteLine stamp & txtline & oSS.sLastErrorMsg WScript.Quit end if 'Create a SO_InvoicePrinting_rpt Print Object for use Set oPrint = oPVX.NewObject("SO_InvoicePrinting_rpt", oSS) ' Terminate UI if you need to avoid screen prompts or ' do not terminate ui if you want to Print to preview 'oSS.nTerminateUI() ' Log that we have created the objects correctly. stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "All Sage setup has passed successfully. Starting print routines for SO_InvoicePrinting_rpt." objLog.WriteLine stamp & txtline ' Check if BatchEnabled has been set for the Print Object being used If CBool(oPrint.nBatchEnabled) Then ' Set the BatchNo for the Print Object retVal = oPrint.nSelectBatch(BatchNo) If retval=0 Then 'MsgBox("Select batch failed: " & oPrint.sLastErrorMsg) stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "Return code " & retVal & " from nSelectBatch call SO_InvoicePrinting_rpt. Exiting script. " objLog.WriteLine stamp & txtline & oPrint.sLastErrorMsg WScript.Quit End If Else stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "oPrint.nBatchEnabled returned false. Exiting script. " objLog.WriteLine stamp & txtline & oPrint.sLastErrorMsg WScript.Quit End If retval = oPrint.nSelectReportSetting("PSP") retval = oPrint.nSetKeyValue("ReportSetting$", "PSP") RetVal = oPrint.nSetKeyValue("RowKey$", "1") retval = oPrint.nSetKey() ' Write report setting to memory 'retval = oPrint.nWrite() 'delay one second WScript.Sleep 1000 ' Call ProcessReport to execute the printout ' ProcessReport(Destination) ' Available Print destinations ' PRINT - print to printer ' DEFERRED - print to deferred ' PREVIEW - preview requires UI retVal = oPrint.nProcessReport("ELECTRONIC DELIVERY") if retVal = 0 then stamp = cstr(year(Now)) & "-" & right("00" & cstr(month(Now)), 2) & "-" & right("00" & cstr(day(Now)), 2) & " " & right("00" & cstr(hour(Now)), 2) & ":" & right("00" & cstr(minute(Now)), 2) & ":" & right("00" & cstr(second(Now)), 2) & ". printInvoiceRec.vbs: " txtline = "Return code " & retVal & " from nProcessReport call SO_InvoicePrinting_rpt. Exiting script. " objLog.WriteLine stamp & txtline & oPrint.sLastErrorMsg WScript.Quit end if Any assistance would be appreciated. Thanks, in advance.
↧