BOI Print PickingSheet resets form code to STANDARD

SOLVED

Hi everyone, would you please have a look at this and see why this is running erratically?  I've seen some sample scripts here and there, and the bulk of my script is from the other posts on this forum.  I must be misunderstanding what objects and what properties/values must be set in order to achieve a successful print job, and I'm a bit lost now.  The issues are the the scripts do not run consistently, and breaks when a certain user action happens .  please read below for detail.   

Objectives

To have a list of sales orders in Excel workbook for user to print Picking Sheet of one or many orders.  The workbook is expected to be open throughout the day. 

Conditions and Considerations

  1. Sage 100c Advanced 2017 (5.40.3.0) & VBA.
  2. The form code used in this script "PICKSHEET-KY" exists in SY_ReportSetting.  This is a heavily used form code.  Using a newly created form code in the script did not change the behavior.
  3. This script successfully prints after manually launching a Picking Sheet Printing task from the launcher, physically type in the form code in the GUI, and process an order.
  4. The script will continue to print UNTIL a picking sheet is printed with the same form code from the PickingSheet Quick Print UI launched from the Sales Order Entry UI through clicking the button.  Doing #3 will make it work again always.  Doing #4 will break it always.
  5. Whether the script prints or not, it always resets the form code of both Picking Sheet Printing and Quick Picking Sheet Printing to "STANDARD" for the user.
  6. SetKeyValue and SetValue for PrintPickshee() seems unnecessary since commenting them out does not change the behavior, and it still prints in the condition #3 above. 
    1. All other posts with sample scripts included this, as well as some BOI training documents so I'm a bit perplexed on this too.

'Project-Level Variable Declaration

'public objects  below are used so that the login prompt at open can maintain the objects in scope until the workbook is closed

Public oScript As Object
Public oSS As Object

'Below collection is updated when the user's order selection changes.  
Public colSelectedOrders as New Collection


Module code:

Note: Login() is called at Workbook open.  Error checking and cleanup lines have been omitted.

 

Public Sub Login()

****Script (oScript),  Session (oSS) object intantiation ommitted****

    retval = nSetUser("UserID","Password")
    retval = nSetCompany("Company")
    sDate = oSS.sModuleDate
    retval = nSetDate("S/O", sDate)
    retval = oSS.SetModule("S/O")
    oSS.nSetProgram (oSS.nLookupTask("SO_PickingSheetPrinting_UI"))
End Sub

All errors mentioned below are from oPickPrint object (SO_PickingSheetPrinting_rpt)

Public Sub PrintPicksheet()
    Dim oPickPrint as Object, oSoEntry as object
    Dim sSelectedOrders as string : sSelectedOrders = "0123457" 'This variable is updates when a Collection Obj colSelectedOrders changes
    Dim sLastFormUsed as string : sLastFormUsed = "PICKSHEET-KY"
   'Initialize object
   
        
        
        Call Login 'In case the user has been kicked out or error foces oSS to go out of scope
        
        Set oPickPrint = oScript.NewObject("SO_PickingSheetPrinting_rpt", oSS)
    
    'Set UI termination
        Select Case sPrintMode 'sPrintMode = value of combobox on form
            Case "PRINT", "DEFFERED"
                retavl = oSS.nTerminateUI()
            Case Else
                retavl = oSS.nInitiateUI()
        End Select
        
    'Set Template
        Dim sLastFormUsed As String
        sLastFormUsed = oPickPrint.sGetLastForm() 'The value is PICKSHEET-KY
            If sLastFormUsed = "" Then 'Something happened to clear the form code from the last run.  Assign from the stored value in worksheet
                sLastFormUsed = ThisWorkbook.Worksheets("ProgramProperties").Range("B4").value
                Else
                ThisWorkbook.Worksheets("ProgramProperties").Range("B4").value = sLastFormUsed
            End If
            
        retavl = oPickPrint.nSelectReportSetting(sLastFormUsed)
        '^ retval=1 
        
        'Below 3 lines return retval = 0 with the error message
        '"The column is not part of the key."
        
        retavl = oPickPrint.nSetKeyValue("ReportID", "SO_PickingSheetPrinting_UI")
        retavl = oPickPrint.nSetKeyValue("ReportSetting$", sLastFormUsed)
        retavl = oPickPrint.nSetKeyValue("RowKey$", "1")
        retavl = oPickPrint.nSetKey()
        '^ retval = 2
        
        'Below 6 lines return retval = 1 with the warning messsage
        "The S/O0000000001SO_PICKINGSHEETPRINTING_UI    PICKSHEET-KY        00001 is invalid
        
        retavl = oPickPrint.nSetValue("SelectField$", "Order Number")
        retavl = oPickPrint.nSetValue("SelectFieldValue$", "Order Number")
        retavl = oPickPrint.nSetValue("Tag$", "TABLE=SO_SALESORDERHEADER; COLUMN=SALESORDERNO$")
        retavl = oPickPrint.nSetValue("Operand$", "=")
        retavl = oPickPrint.nSetValue("Value1$", sSelectedOrders)
        retavl = oPickPrint.nWrite()
        
    'Updated Selected Sales Order's PrintPicksheet setting
        Set oSoEntry = oScript.NewObject("SO_SalesOrder_Bus", oSS)
        
        For i = 1 To colSelectedOrders.Count 'Loop through collection object that stores user selected order numbers
            retVal = oSoEntry.nSetKey(colSelectedOrders.Item(i))
            retVal = oSoEntry.nSetValue("PrintPickingSheets$", "Y")
            retVal = oSoEntry.nWrite()
        Next i
        
        Set oSoEntry = nothing
    
    'Process 
        retVal = oPickPrint.nProcessReport(sPrintMode)
        ^retval = 0, error message "Data is not selected for report printing"
        
    'Cleanup
        Set oPickPrint = Nothing
    End sub

What am I missing here to be able to....

  1. Print successfully every time (given the form code exists)?
  2. Make the form code not reset to Standard?

Ken

  • +1
    verified answer

    You shouldn't have to bother with the following code since printing the sales order through picking sheet printing should update it.

        'Updated Selected Sales Order's PrintPicksheet setting
            Set oSoEntry = oScript.NewObject("SO_SalesOrder_Bus", oSS)
            
            For i = 1 To colSelectedOrders.Count 'Loop through collection object that stores user selected order numbers
                retVal = oSoEntry.nSetKey(colSelectedOrders.Item(i))
                retVal = oSoEntry.nSetValue("PrintPickingSheets$", "Y")
                retVal = oSoEntry.nWrite()
            Next i
            
            Set oSoEntry = nothing

    If you are only doing one sales order at a time, i don't see any reason not to use the quick print process instead of trying to set the criteria using "rows" but if you must do it that way, here is an excerpt from one of my scripts.  You are missing 2 key points, the module code and the company key.  In addition to those missing, the row key actually needs to be zero padded on the left so it is five characters long.

    	' Set the selection criteria.
    	' If I'm not mistaken, KeyReference should be set for multi-part keys and should be something like this, "<APDivisionNo$+VendorNo$>". The arrows must be included and wrap the fields that make up the multi-part key.
    	' Tag must include the table name and column name like this, "Table=CI_Item;Column=ItemCode$;".
    	' Increment nRowKey for each row used in the selection.
    	' This is required if you need to filter the report and will be using ProcessReport instead of ProcessReportWorkTable.
    	' It can still be used to filter the report if you use ProcessReportWorkTable.
    		scModuleCode = "" : oReport_Rpt.nGetValue "cModuleCode$", scModuleCode
    		scCompanyKey = "" : oReport_Rpt.nGetValue "cCompanyKey$", scCompanyKey
    		scReportID = "" : oReport_Rpt.nGetValue "cReportID$", scReportID
    		
    		nRowKey = 0 
    
    		' Row 1
    			nRowKey = nRowKey + 1 
    			oReport_Rpt.nSetKeyValue "ModuleCode$", scModuleCode
    			oReport_Rpt.nSetKeyValue "CompanyKey$", scCompanyKey
    			oReport_Rpt.nSetKeyValue "ReportID$", scReportID
    			oReport_Rpt.nSetKeyValue "ReportSetting$", UCase(sReportSetting)
    			oReport_Rpt.nSetKeyValue "RowKey$", Right("00000" & CStr(nRowKey), 5) 
    			oReport_Rpt.nSetKey
    			oReport_Rpt.nSetValue "SelectField$", "Taxable Sales Amt" 
    			oReport_Rpt.nSetValue "SelectFieldValue$", "Taxable Sales Amt" 
    			oReport_Rpt.nSetValue "KeyReference$", "<(((TaxableSalesAmt + NonTaxableSalesAmt + FreightAmt + SalesTaxAmt) - DiscountAmt) - DepositAmt)>"
    			oReport_Rpt.nSetValue "Tag$", "Table=AR_InvoiceHistoryHeader;Column=<(((TaxableSalesAmt + NonTaxableSalesAmt + FreightAmt + SalesTaxAmt) - DiscountAmt) - DepositAmt)>;"
    			oReport_Rpt.nSetValue "Operand$", "G" 
    			oReport_Rpt.nSetValue "Value1$", "1" 
    			oReport_Rpt.nSetValue "Value2$", "" 
    			oReport_Rpt.nWrite 
    			
    		' Row 2
    			nRowKey = nRowKey + 1
    			oReport_Rpt.nSetKeyValue "ModuleCode$", scModuleCode 
    			oReport_Rpt.nSetKeyValue "CompanyKey$", scCompanyKey 
    			oReport_Rpt.nSetKeyValue "ReportID$", scReportID 
    			oReport_Rpt.nSetKeyValue "ReportSetting$", UCase(sReportSetting)
    			oReport_Rpt.nSetKeyValue "RowKey$", Right("00000" & CStr(nRowKey), 5) 
    			oReport_Rpt.nSetKey 
    			oReport_Rpt.nSetValue "SelectField$", "Invoice Due Date" 
    			oReport_Rpt.nSetValue "SelectFieldValue$", "Invoice Due Date" 
    			oReport_Rpt.nSetValue "KeyReference$", "InvoiceDueDate$"
    			oReport_Rpt.nSetValue "Tag$", "Table=AR_InvoiceHistoryHeader;Column=InvoiceDueDate$;"
    			oReport_Rpt.nSetValue "Operand$", "R" 
    			oReport_Rpt.nSetValue "Value1$", "20200210" 
    			oReport_Rpt.nSetValue "Value2$", "20200510" 
    			oReport_Rpt.nWrite 

    Here's a very simple example from one of my scripts showing the quick print process, in this one, i'm exporting the report to a PDF but you can just change it to PRINT instead.

    sReportSetting = "WORK TICKET CS"
    sExportPath = "\\server\MAS\" & soNo & ".pdf"
    If oSession.nSetProgram(oSession.nLookupTask("SO_SalesOrderQuickPrint_UI")) > 0 Then
    	Set oSO_SalesOrderPrinting_Rpt = oSession.oNewObject("SO_SalesOrderPrinting_Rpt")
    	If oSO_SalesOrderPrinting_Rpt.nInitReportEngine() > 0 Then
    		oSO_SalesOrderPrinting_Rpt.nReportType = 6
    		If oSO_SalesOrderPrinting_Rpt.nSelectReportSetting(sReportSetting) > 0 Then
    			oSO_SalesOrderPrinting_Rpt.sQuickPrint = soNo
    			If CBool(oSO_SalesOrderPrinting_Rpt.nPDFEnabled) Then oSO_SalesOrderPrinting_Rpt.nPDFSilent = 1
    			retVal = 0 : retVal = oSO_SalesOrderPrinting_Rpt.nSetExportOptions(5, sExportPath)
    			retVal = 0 : retVal = oSO_SalesOrderPrinting_Rpt.nProcessReport("EXPORT")
    		End If
    	End If
    	Set oSO_SalesOrderPrinting_Rpt = Nothing
    End If

    Also, if you always want the form used that is specified in a cell in the workbook, there is no reason to bother with the GetLastForm method, you should always use the SelectReportSetting method for the form code/report setting that you want to use via BOI.

  • 0 in reply to David Speck

    Thanks David.  Yah multiple orders often need to be printed for this one.  Thanks for pointing out the keys, I see that now in the table definition.  I modified, and cleaned up a bit per your suggestion. The techniques you showed me on some variable assignments are awesome.  I also put all logics in one test sub to weed out any other possible causes for errors (see  below code block) .But I must be still missing something else. The Line#57  oPickPrint.nWrite()  fails, and the oSession object also throws an error at that line.

    • Retval=0
    • oSS.sLastErrorMsg = "Error #13: File access mode invalid"

    All other retvals are 1 (except for SetKey returns 2 for new).  The user has full permission at any level or any security events, 

     

    Option Explicit
    Sub PrintPicksheet()
    
        'Initialize variables
            Dim oSession As Object, oScript As Object, oPickPrint As Object
            Dim sDate As String: sDate = ""
            Dim scModuleCode As String: scModuleCode = ""
            Dim scCompanyKey As String: scCompanyKey = ""
            Dim scReportID As String: scReportID = ""
            Dim sReportSetting As String: sReportSetting = ""
            Dim oReg As Object
            Dim retval As Long
            Dim nRowKey As Integer
            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", PathHome)
                If retval <> 0 Then
                  oReg.GetExpandedStringValue HKEY_CURRENT_USER, "Software\ODBC\ODBC.INI\SOTAMAS90", "Directory", PathHome
                End If
         'Instantiate Session & Scrip Obj
            Set oScript = CreateObject("ProvideX.Script")
            oScript.Init (PathHome)
            Set oSession = oScript.NewObject("SY_Session")
            retval = oSession.nInitiateUI()
         
         'Log in user
            
            retval = oSession.nSetUser("me", "pass")
            retval = oSession.nSetCompany("TST")
            retval = oSession.nSetModule("S/O")
            sDate = oSession.sModuleDate
            retval = oSession.nSetDate("S/O", sDate)
         'Instantiate Sec Obj
            oSession.nSetProgram (oSession.nLookupTask("SO_PickingSheetPrinting_UI"))
            Set oPickPrint = oScript.NewObject("SO_PickingSheetPrinting_rpt", oSession)
        
        'Assign print params
            scModuleCode = "": retval = oPickPrint.nGetValue("cModuleCode$", scModuleCode)
            scCompanyKey = "": retval = oPickPrint.nGetValue("cCompanyKey$", scCompanyKey)
            scReportID = "": retval = oPickPrint.nGetValue("cReportID$", scReportID)
            sReportSetting = "PICKSHEET-KY"
                nRowKey = 1
                retval = oPickPrint.nSelectReportSetting(sReportSetting)
                retval = oPickPrint.nSetKeyValue("ModuleCode$", scModuleCode)
                retval = oPickPrint.nSetKeyValue("CompanyKey$", scCompanyKey)
                retval = oPickPrint.nSetKeyValue("ReportID$", scReportID)
                retval = oPickPrint.nSetKeyValue("ReportSetting$", UCase(sReportSetting))
                retval = oPickPrint.nSetKeyValue("RowKey$", Right("00000" & CStr(nRowKey), 5))
                retval = oPickPrint.nSetKey()
                retval = oPickPrint.nSetValue("SelectField$", "Order Number")
                retval = oPickPrint.nSetValue("SelectFieldValue$", "Order Number")
                retval = oPickPrint.nSetValue("KeyReference$", "<SALESORDERNO$>")
                retval = oPickPrint.nSetValue("Tag$", "TABLE=SO_SALESORDERHEADER; COLUMN=<SALESORDERNO$>")
                retval = oPickPrint.nSetValue("Operand$", "=")
                retval = oPickPrint.nSetValue("Value1$", "0143410")
                retval = oPickPrint.nWrite()
                On Error Resume Next
                retval = oPickPrint.nProcessReport("PREVIEW")
                
            retval = oSession.nLogoffUser()
            retval = oSession.nCleanup()
            retval = oSession.DropObject()
            Set oPickPrint = Nothing
            Set oSession = Nothing
            Set oScript = Nothing
    
    End Sub

    Also, throwing in SelectReportSetting causes the form code in GUI to be reset to STANDARD.  I can't find any reference to the mechanism and how to mitigate it.   

    Any idea??

    Ken 

    ----EDITED 1/17/2021

    The above code was missing  retval = oPickPrint.nSelectReportSetting(sReportSetting) before the series of SetKeyValue() methods, which caused the #Error 13 mentioned.   Adding  retval = oPickPrint.nSelectReportSetting(sReportSetting) alleviated the error but resulted in retval = 0 at nProcessReport, with the error message "Data is not selected for report printing"

    Witt the nSelectReportSetting method added, replacing the below block....

                retval = oPickPrint.nSetValue("SelectField$", "Order Number")
                retval = oPickPrint.nSetValue("SelectFieldValue$", "Order Number")
                retval = oPickPrint.nSetValue("KeyReference$", "<SALESORDERNO$>")
                retval = oPickPrint.nSetValue("Tag$", "TABLE=SO_SALESORDERHEADER; COLUMN=<SALESORDERNO$>")
                retval = oPickPrint.nSetValue("Operand$", "=")
                retval = oPickPrint.nSetValue("Value1$", "0143410")
                retval = oPickPrint.nWrite()

    with the following, where the "SalesOrderNo$" consists of ONE sales order number, the code will process as intended without resetting the form code to STANDARD

    oPickPrint.sQuickPrint = "SalesOrderrNo$"

  • 0 in reply to Kentaro

    So when doing multiple sales orders, are you passing them to the object once as a comma delimited value with the operand set for "Equal To" or or you looping on each sales order in the collection?

    If looping, you might as well use the quick print process instead.

    Two things i see missing from your code when comparing against some of mine is calling the InitReportEngine method and setting the ReportType property.  Below is an excerpt from a script of mine that was originally used from a button script inside of sage 100 so i adapted it for external use.  This script was used to export the sales order to a pdf, since you are not exporting, you can probably omit the line with SetExportOptions method and just change the argument passed to the ProcessReport method to "PRINT".

    sSalesOrderNo = "1234567"
    sReportSetting = "PICKING SHEET" 
    sMessage = ""
    
    sPathRoot = "" : sPathRoot = oSession.PathCSRoot
    Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
    If Not(oFileSystemObject.FolderExists(sPathRoot)) Then sPathRoot = oSession.PathRoot
    Set oFileSystemObject = Nothing
    sAttachmentPath = sPathRoot
    Set objRegExp = New RegExp
    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    objRegExp.Pattern = "[(?*"",\\<>&#~%{}+_.@:\/!;]+"
    sFieldValue = objRegExp.Replace(sSalesOrderNo, "")
    Set objRegExp = Nothing
    sAttachmentFileName = "SalesOrder_"  & sSalesOrderNo & "_" & oScript.Evaluate("DTE(0:""%Y-%Mz-%Dz"")") & ".pdf"
    sAttachmentFileName = sPathRoot & "Home\TextOut\" & sAttachmentFileName
    			
    oSession.sLastErrorNum = "" : oSession.sLastErrorMsg = "" : nSO_SalesOrderPrinting_Rpt_SecObj = 0 : nSO_SalesOrderPrinting_Rpt_SecObj = oSession.nSetProgram(oSession.nLookupTask("SO_SalesOrderPrinting_UI"))
    If nSO_SalesOrderPrinting_Rpt_SecObj <> 0 Then
    	On Error Resume Next
    	oSession.sLastErrorNum = "" : oSession.sLastErrorMsg = "" : Set oSO_SalesOrderPrinting_Rpt = oSession.oNewObject("SO_SalesOrderPrinting_Rpt")
    	On Error Goto 0
    	If IsObject(oSO_SalesOrderPrinting_Rpt) Then
    		oSO_SalesOrderPrinting_Rpt.sLastErrorNum = "" : oSO_SalesOrderPrinting_Rpt.sLastErrorMsg = "" : nInitReportEngine = 0 : nInitReportEngine = oSO_SalesOrderPrinting_Rpt.nInitReportEngine()
    		If nInitReportEngine <> 0 Then
    			oSO_SalesOrderPrinting_Rpt.nReportType = 6
    			If sReportSetting <> "" Then 
    				oSO_SalesOrderPrinting_Rpt.sLastErrorNum = "" : oSO_SalesOrderPrinting_Rpt.sLastErrorMsg = "" : nRetVal = 0 : nRetVal = oSO_SalesOrderPrinting_Rpt.nSelectReportSetting(sReportSetting)
    				If nRetVal > 0 Then
    					If oSO_SalesOrderPrinting_Rpt.nPDFEnabled = 1 Then oSO_SalesOrderPrinting_Rpt.nPDFSilent = 1
    					oSO_SalesOrderPrinting_Rpt.sQuickPrint = sSalesOrderNo
    					oSO_SalesOrderPrinting_Rpt.nSetExportOptions 5, sAttachmentFileName
    					oSO_SalesOrderPrinting_Rpt.sLastErrorNum = "" : oSO_SalesOrderPrinting_Rpt.sLastErrorMsg = "" : nRetVal = 0 : nRetVal = oSO_SalesOrderPrinting_Rpt.nProcessReport("Export")
    					If nRetVal <= 0 Then
    						If sMessage <> "" Then sMessage = sMessage & vbCrlF & " " & vbCrLf End If : sMessage = sMessage & "Method failed in class SO_SalesOrderPrinting_Rpt." _
    							& vbCrLf & "Method: " & "nProcessReport" _
    							& vbCrLf & "RetVal: " & "nRetVal" _
    							& vbCrLf & "Error Number: " & oSO_SalesOrderPrinting_Rpt.sLastErrorNum _
    							& vbCrLf & "Error Message: " & oSO_SalesOrderPrinting_Rpt.sLastErrorMsg
    					End If
    				End If
    			End If
    		Else
    			If sMessage <> "" Then sMessage = sMessage & vbCrlF & " " & vbCrLf End If : sMessage = sMessage & "Method failed in class SO_SalesOrderPrinting_Rpt." _
    				& vbCrLf & "Method: " & "InitReportEngine" _
    				& vbCrLf & "RetVal: " & "nInitReportEngine" _
    				& vbCrLf & "Error Number: " & oSO_SalesOrderPrinting_Rpt.sLastErrorNum _
    				& vbCrLf & "Error Message: " & oSO_SalesOrderPrinting_Rpt.sLastErrorMsg
    		End If
    		Set oSO_SalesOrderPrinting_Rpt = Nothing
    	Else
    		If sMessage <> "" Then sMessage = sMessage & vbCrlF & " " & vbCrLf End If : sMessage = sMessage & "Unable to get handle to SO_SalesOrderPrinting_Rpt." _
    			& vbCrLf & "Error Number: " & oSession.sLastErrorNum _
    			& vbCrLf & "Error Message: " & oSession.sLastErrorMsg
    	End If
    Else
    	If sMessage <> "" Then sMessage = sMessage & vbCrlF & " " & vbCrLf End If : sMessage = sMessage & "Unable to set program to SO_SalesOrderPrinting_UI." _
    		& vbCrLf & "Error Number: " & oSession.sLastErrorNum _
    		& vbCrLf & "Error Message: " & oSession.sLastErrorMsg
    End If
    
    If oSession.nUI <> 0 Then If sMessage <> "" Then oSession.oUI.nMessageBox "", sMessage

  • 0 in reply to David Speck

    I'm passing the comma delimited order numbers with the Equal To operand once.  The delimited variable is produced by looping through the VBA's collection object at the time of change event in Excel, so it's quick.

    I made another sub for a quick print with ReportType and initReportEngine added.  I also made a different sub with your PDF export script with very minor modification to cope with my environment/variables.  Both your export code, AND my new quick print code with SO_PickingSheetQuickPrint_UI print properly.  A good find was that passing multiple order numbers as a comma delimited string to QuickPrint$ prints multiple orders, so no looping was needed.   EDIT 1/17/2021 - See above response and edit from the same date for why this is crossed ouut.

    BUT as far as the form code in GUI goes, the result was identical for both codes.  They successfully print the target form code specified by nSelectReportSetting, but the Form Code for the GUI resets to STANDARD whether the BOI codes processes PRINT, PRIVEW, or EXPORT.  

    Only thing I can think of are...some setting flagging defaulting to the the STANDARD form code is set to true by default, a missing property is forcing it to change, or may be there is a method I'm supposed to execute after ProcessReport method to write the last form used.  But I don't see anything like that in object reference.  

    I'm completely lost now.  With your PDF export script, the only things different between your code and mine I can see are the oScript init path, user credentials, form code, and order number.

  • 0 in reply to David Speck

    David, I got it.  What I was missing was the following line after the SelectReportSetting method.

    retval = oPickPrint.nSetKeyValue("ReportSetting$", sReportSetting)

    With this line, the form code sticks. I'm a bit confused as to why my environment (Sage 100c 2017 Advanced 5.40.3.0) needs it, while other environments, presumably yours, don't need it.  Plus this is a part of the key columns....But oh well, I'm leaving this project as completed and leave that question for later.  

    Thanks again for your time and help!

  • 0 in reply to Kentaro

    That's odd, i do have that included in my example.  By any chance, between my examples and your code, did you use the wrong variable name passed as the second argument?

    I make it a habit to use SetKeyValue on the fields in the same order that they appear in the primary key.

  • 0 in reply to David Speck

    I have Option Explicit declared and I was getting printing/previewing the target form code, so i'm doubtful about the wrong variable but I'll check.

    The script that's working for me now uses Quick Print UI.  It's basically a carbon copy of your PDF export scripts, in which you don't have any of the key values set.  My original script assigns the key values in the exact order you just showed me too.  There are lots of things I can scrutinize.  

    I'll post my finding next week.  

  • 0 in reply to Kentaro

    David i seemed to have solved "some" of the puzzle. 

    1. The original code in my question had a typo.  This was the root cause of many errors. 
      1.  posted - retavl = oPickPrint.nSetKeyValue("ReportID", "SO_PickingSheetPrinting_UI")
      2. Correct -  retavl = oPickPrint.nSetKeyValue("ReportID$", "SO_PickingSheetPrinting_UI")
    2. Using SO_PickingSheetPrinting_rpt to print multiple orders (instead of quick print)
      1. Your code block that includes a series of SetValue was needed, though in my case KeyReference$ wasn't needed.  I'm not familiar with what this does so I can't comment whether leaving it out is a good idea or not.  
      2. My original code, with the correction above turned out to be a working script BUT unlike your environment, my environment required the Sales Order's PrintPickingSheets$ value to be updated to "Y".  Otherwise the report object will return "Data is not selected for report printing." error when ProcessRerport() is issued.  
    3. Why the form code resets to STANDARD
      1. After issuing the ProcessReport() method, I had to issue the UpdateLastForm() method inherited from the SY_Form object.  Then the form code used will stick. 

    Now one last problem remains. 

    if the user prints the picksheet through QuickPrint GUI, then the script (the non-quick print script) will return "data not selected" error, even though PrintPickingSheet$ is "Y".  After the user print/preview any report from Picking Sheet Print GUI (not Quick Print), then the script will work again.   

  • 0 in reply to Kentaro

    The last piece of puzzle has been solved.  It was the report options.  I looked into whether certain types of sales orders weren't printing, and found that back orders weren't printing,  Sure enough, the INCLUDEBACKORDERLINES$ option was set to "Y" in GUI for the user but  the report option string shown in the script showed it was set to "N".  So I passed the entire option strings to the report object by issuing SetOptions(sOptions).  Now the script is behaving exactly as expected.

    Many thanks to you David and your expertise.  Now i have much more understanding in how these objects work, where to look for additional methods and properties, and 2 additional working scripts! 

    I'll share the entire script later with comments later after i'm done scrubbing it.  Thanks again.  

  • 0 in reply to Kentaro

    I was going to bring up the report options but then i didn't see any that were related to orders where the sales order or picking sheet had already been printed, like the one invoice printing has.  So then i didn't think it was worth pursuing. 

    FYI, this is code that i use to deal with report options.  You first get the current options string, then use the ReplaceDefault method to set the option you want, then use SetOptions with the modified options string.

    	
    ' Get the current report options.
    	sReportOptions = "" : oReport_Rpt.nGetOptions sReportOptions
    
    ' Replace the report option specified in the second argument with the value specified in the third argument.
    	oReport_Rpt.nReplaceDefault sReportOptions, "CB_UNPAIDINVSONLY$", "Y"
    	oReport_Rpt.nReplaceDefault sReportOptions, "DB_PRINTCOMMENT$", "F"
    	oReport_Rpt.nReplaceDefault sReportOptions, "DB_PAPERLESSOFFICEOUTPUT$", "1"
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_INVMSG1$", ""
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_HISTMSG1$", ""
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_INVMSG2$", ""
    	oReport_Rpt.nReplaceDefault sReportOptions, "ML_HISTMSG2$", ""
    	
    ' Set the modified report options.
    	oReport_Rpt.nSetOptions sReportOptions