Sales Order Invoices don't get emailed from BOI script when run with Windows Task Scheduler.

I created a BOI script that selects a batch of invoices, PDF's them, emails them, updates and PDF's the sales register and updates and PDF's the DTR in 2022 Advanced.  The script works fine when run manually from the desktop.  When running it from Windows Task Scheduler, the invoices don't get PDF'd and they don't get emailed but the sales register and DTR both get PDF'd.  The Task Scheduler task is set up under the same Windows login as I am using when triggering the script manually and it's set to run elevated.  The BOI script logs into Sage with the same user/pw as I use when running manually.  The "old" fix for this was to copy the [PAPERLESS] section from sota.ini to pvx.ini.  However, there is no [PAPERLESS] section in sota.ini anymore.  Any suggestions would be appreciated.

Parents
  • 0

    Figured it might help if I included the section of the script that I'm having the issue with.

    retVal = oSS.nSetProgram(oSS.nLookupTask("SO_InvoicePrinting_UI"))
    Set oSO_InvPrint = oPVX.NewObject("SO_InvoicePrinting_rpt", oSS)
    
    retVal = oSO_InvPrint.nSelectBatch(vBatchNo)
    retVal = oSO_InvPrint.nSelectReportSetting("TEST")  'Change "CUSTOM" to the correct form name
    
    oSO_InvPrint.nEmailSelected = 1
    Set oPaperless = oSO_InvPrint.ocoPLCommon
    oPaperless.sFormPrintUISelection = "2"  'Electronic Delivery Only (Includes PDF)
    oSO_InvPrint.oEmailEngineObj.nEESilent = 1
    retVal = oPaperless.nElectronicDelivery("",0,oSO_InvPrint.oEmailEngineObj,0, "","",1)
    
    If vPrintAlreadyPrinted = "Y" Then  'Emulates checking the "Print Invoices Already Printed" checkbox on the printing screen
    	oSO_InvPrint.nGetOptions sReportOptions
    	oSO_Invprint.nReplaceDefault sReportOptions, "CB_PRINTINVOICESPRINTED$", "Y"
    	oSO_Invprint.nSetOptions sReportOptions
    End If
    
    retVal = oSO_InvPrint.nDisableUseOfUI()	
    retVal = oSO_InvPrint.nProcessReport(vDestination)
    retVal = oSO_InvPrint.nEndOfPDFConverterJob()
    retVal = oSO_InvPrint.nUpdateLastForm()  'Make Sage remember the last form used to print the invoices
    oSO_InvPrint.DropObject		
    'msgbox("Invoices Printed")



Reply
  • 0

    Figured it might help if I included the section of the script that I'm having the issue with.

    retVal = oSS.nSetProgram(oSS.nLookupTask("SO_InvoicePrinting_UI"))
    Set oSO_InvPrint = oPVX.NewObject("SO_InvoicePrinting_rpt", oSS)
    
    retVal = oSO_InvPrint.nSelectBatch(vBatchNo)
    retVal = oSO_InvPrint.nSelectReportSetting("TEST")  'Change "CUSTOM" to the correct form name
    
    oSO_InvPrint.nEmailSelected = 1
    Set oPaperless = oSO_InvPrint.ocoPLCommon
    oPaperless.sFormPrintUISelection = "2"  'Electronic Delivery Only (Includes PDF)
    oSO_InvPrint.oEmailEngineObj.nEESilent = 1
    retVal = oPaperless.nElectronicDelivery("",0,oSO_InvPrint.oEmailEngineObj,0, "","",1)
    
    If vPrintAlreadyPrinted = "Y" Then  'Emulates checking the "Print Invoices Already Printed" checkbox on the printing screen
    	oSO_InvPrint.nGetOptions sReportOptions
    	oSO_Invprint.nReplaceDefault sReportOptions, "CB_PRINTINVOICESPRINTED$", "Y"
    	oSO_Invprint.nSetOptions sReportOptions
    End If
    
    retVal = oSO_InvPrint.nDisableUseOfUI()	
    retVal = oSO_InvPrint.nProcessReport(vDestination)
    retVal = oSO_InvPrint.nEndOfPDFConverterJob()
    retVal = oSO_InvPrint.nUpdateLastForm()  'Make Sage remember the last form used to print the invoices
    oSO_InvPrint.DropObject		
    'msgbox("Invoices Printed")



Children
  • 0 in reply to Ray P

    retVal = oSO_InvPrint.nSelectReportSetting("TEST")   This form code exists in Sage and had been printed to by the user in the script.

  • 0 in reply to Ray P

    You could save yourself a lot of time with isolating this by adding small bit of logging support to the script.

    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(sEnhancementPath  & "\" & sFile & "." & "log") Then
    Set ts = fso.OpenTextFile(sEnhancementPath  & "\" & sFile & "." & "log", 8)
    Else
    Set ts = fso.CreateTextFile(sEnhancementPath  & "\" & sFile & "." & "log", True)
    End If
    ...
    oObject.sLastErrorMsg = ""
    ...
    ts.WriteLine vbCr & FormatDateTime(Date, vbShortDate) & " " & FormatDateTime(Time, vbLongTime) & vbTab & SCRIPT_ID & "<<method>> retVal =" & retVal & oObject.sLastErrorMsg"