Print Sales Order with Button Script - Not Working for SO on Hold

SOLVED

Scripting Experts,

I am working on a SO Print Script that works fine for regular Sales Orders. But when I try to print a SO that is on hold, I get the following error message. Does anyone know if I have to (and how I would do it) set the Print Orders on Hold Flag? The FormCode that I use has it set by default. The script runs as a button script.

Here is the relevant part of the code:

	Set oSOPrint = oSession.AsObject(oSession.GetObject(sPrintingObject))
	retVal = oSOPrint.SelectReportSetting(sForm)
	oSOPrint.QuickPrint = sSONumber
	retVal = oSOPrint.SetOptions(options)
	oSOPrint.ReportType = 6
	
	retval = oSOPrint.InitReportEngine()
	retval = oSOPrint.SetExportOptions(5, sPath)
	retVal = oSOPrint.ProcessReport("EXPORT")

	sError = oSOPrint.LastErrorMsg

Thanks,

Bastian

  • +1
    verified answer

    You are using the SetOptions method but i don't see in your example where you are setting a value in the "options" variable that you are passing as the argument.

    The value expected to be passed to SetOptions is a semi-colon delimited list of options. The current options string can be retrieved by using GetOptions.

    Here is the options string for Sales Order Printing.

    SORTBY$="O";DB_ORDERTYPE$="A";DB_PRINTCOMMENTS$="P";PRINTORDERSONHOLD$="Y";CB_PRINTBILLOPTIONS$="N";DB_PAPERLESSOFFICEOUTPUT$="";ELECTRONICDELIVERYOPTIONS$="";CB_PRINTLOTSERIALDIST$="N";EMAILADDRESS$="";CB_ALLSTATUSES$="N";CB_ACTIVE$="Y";CB_COMPLETED$="Y";CB_QUOTE$="Y";CB_DELETEDORDER$="N";CB_DELETEDQUOTE$="N";CB_INCLUDEORIGQTY$="N";ML_HISTMSG1$="* This is a reprinted order *";ML_ORDMSG1$="";ML_HISTMSG2$="";ML_ORDMSG2$="";CB_ALLSTATUSES$="N";CB_ACTIVE$="Y";CB_COMPLETED$="Y";CB_QUOTE$="Y";CB_DELETEDORDER$="N";CB_DELETEDQUOTE$="N";CB_INCLUDEORIGQTY$="N";ML_HISTMSG1$="* This is a reprinted order *";ML_ORDMSG1$="";ML_HISTMSG2$="";ML_ORDMSG2$=""

    Here is a snippet from one of my scripts on using the GetOptions, ReplaceDefault, and SetOptions methods. I'm using ReplaceDefault to set the value of the "PRINTORDERSONHOLD$" option to "Y".

    ' Get the current report options.
    	sReportOptions = "" : oReport_Rpt.GetOptions sReportOptions
    
    ' Replace the report option specified in the second argument with the value specified in the third argument.
    	oReport_Rpt.ReplaceDefault sReportOptions, "PRINTORDERSONHOLD$", "Y"
    	
    ' Set the modified report options.
    	oReport_Rpt.SetOptions sReportOptions

  • +1 in reply to David Speck
    verified answer

    David, thanks a lot! That was super helpful and solved my problem. 

    Here is my final working code snippet for reference.

    	'*** Create PDF File
    	Set oSOPrint = oSession.AsObject(oSession.GetObject(sPrintingObject))
    	retVal = oSOPrint.SelectReportSetting(sForm)
    	oSOPrint.QuickPrint = sSONumber
    
    	sOptions = ""
    	retVal = oSOPrint.GetOptions(sOptions)
    	'retMsg = oSession.AsObject(oSession.UI).MessageBox("", sOptions)
    	oSOPrint.ReplaceDefault sOptions, "PRINTORDERSONHOLD$", "Y"
    
    	retVal = oSOPrint.SetOptions(sOptions)
    	oSOPrint.ReportType = 6
    	
    	retval = oSOPrint.InitReportEngine()
    	retval = oSOPrint.SetExportOptions(5, sPath)
    	retVal = oSOPrint.ProcessReport("EXPORT")
    
    	sError = oSOPrint.LastErrorMsg
    
        Set oSOPrint = Nothing