UDF Date filter not working with SO Printing Script - BUG?

SOLVED

Huge thanks to David Speck for your code and your expertise.

I've got a script that works well for printing all SOs, but I'm trying to filter it down using a UDF Date Parameter (UDF_Delivery_By) we have in SO Printing.  I'm certain I have my syntax wrong.  Any suggestions for getting this working?  

The relevant bit of code is below with the lines that are seemingly being ignored in blue .  All orders continue to be printed.  I've checked that the filter works when printing inside of Sage SO Printing.  Also, there are no errors when running the script.  It just prints all SOs not yet printed.

nRowKey = 1
retval = oSO.nSelectReportSetting(sReportSetting)
   ErrorLog retval, "Error setting report setting.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetKeyValue("ModuleCode$", scModuleCode)
   ErrorLog retval, "Error setting module code.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetKeyValue("CompanyKey$", scCompanyKey)
   ErrorLog retval, "Error setting company key.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetKeyValue("ReportID$", scReportID)
   ErrorLog retval, "Error setting report ID.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetKeyValue("ReportSetting$", UCase(sReportSetting))
   ErrorLog retval, "Error setting report setting.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetKeyValue("RowKey$", Right("00000" & CStr(nRowKey), 5))
   ErrorLog retval, "Error setting RowKey", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetKey()
   ErrorLog retval, "Error setting key.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir


retval = oSO.nSetValue("SelectField$", "Order Number")
   ErrorLog retval, "Error selecting order number field.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("SelectFieldValue$", "Order Number")
   ErrorLog retval, "Error selecting field value.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("KeyReference$", "<SALESORDERNO$>")
   ErrorLog retval, "Error setting key reference.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("Tag$", "TABLE=SO_SALESORDERHEADER;COLUMN=~SalesOrderNo$")
   ErrorLog retval, "Error setting tag.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("Operand$", ">") 'all orders
   ErrorLog retval, "Error setting operand.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("Value1$", "") 'all orders
   ErrorLog retval, "Error setting SO No.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir



retval = oSO.nSetValue("SelectField$", "UDF_Delivery_By")
   ErrorLog retval, "Error selecting UDF_Delivery_By field.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("SelectFieldValue$", "UDF_Delivery_By")
   ErrorLog retval, "Error selecting UDF_Delivery_By field value.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("Tag$", "TABLE=SO_SALESORDERHEADER;COLUMN=~UDF_Delivery_By$")
   ErrorLog retval, "Error setting UDF_Delivery_By tag.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("Operand$", "L")
   ErrorLog retval, "Error setting UDF_Delivery_By operand.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
retval = oSO.nSetValue("Value1$", "20211203")
   ErrorLog retval, "Error setting UDF_Delivery_By value 1.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir


retval = oSO.nWrite()
   ErrorLog retval, "Error writing.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir


On Error Resume Next
retval = oSO.nProcessReport("PRINT")
   ErrorLog retval, "Error printing.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir 
if retval <> 0 then
   ErrorLog retval, "Sales Order(s) printed successfully.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
end if

Parents
  • 0

    What you are using for the UDF_Delivery_By$ looks correct.  However, for the SalesOrderNo$, if you are not selecting a range or actual less/greater than value, i don't think you need to bother including it.  Also, a better way to get ALL is to use A as the operand, i don't think you would have to bother setting Value1$ or Value2$ in this case.  Refer to the following link for more info on report selections.

    File Layouts and Program Information - SY_Selection (sage.com)

  • 0 in reply to David Speck

    Thanks, David.  I have already tried excluding the portion for SalesOrderNo$ selection, but it did not help.  I am still getting all unprinted SOs and the date parameter is being ignored.  Any other suggestions?  And thank you very much for your feedback.

  • 0 in reply to David Speck

    Good idea.  UDF is spelled correctly, though a second set of eyes never hurts.  And here is the DFDM.. Looks like your typical date..

  • 0 in reply to David Speck

    I'm beginning to think I have encountered a bug.

  • 0 in reply to n0tgunshy2

    What version and edition are you on?

    I've tested selecting sales orders by a date UDF on my 2018 Advanced install running in MAS90 mode and it works using the "=" or "L" operand.  However, I did notice that when using the SO_SalesOrderPrinting_RPT class, if the PrintSalesOrders$ field on the target sales order is not "Y", then it is not selected.  The SO_SalesOrderPrinting_UI class has an UpdatePrintSOFlag method which I suspect is used in conjunction with the UI's Select button and toggles the flag so the RPT class can select it.

    So while using the SO_SalesOrderPrinting_RPT during testing, I had to use Sales Order Entry to manually toggle PrintSalesOrders$ back to "Y" after each test preview.

    This is the code I'm using to write the selection criteria for testing purposes.

    sReportSetting = "Standard"
    sLookupTask = "SO_SalesOrderPrinting_UI"
    sNewObjectName = "SO_SalesOrderPrinting_RPT"
    If oSession.nSetProgram(oSession.nLookupTask(sLookupTask)) > 0 Then
    	nReport_Rpt = 0 : nReport_Rpt = oSession.nNewObject(sNewObjectName)
    	If nReport_Rpt > 0 Then
    		Set oReport_Rpt = oSession.oGetObject(sNewObjectName)
    				
            oReport_Rpt.nSelectReportSetting sReportSetting
            
            nRowKey = 0 
            
    		nRowKey = nRowKey + 1	
            oReport_Rpt.nSetKeyValue "ModuleCode$", oSession.sModuleCode 
            oReport_Rpt.nSetKeyValue "CompanyKey$", oSession.sCompanyKey 
            oReport_Rpt.nSetKeyValue "ReportID$", oReport_Rpt.sReportID 
            oReport_Rpt.nSetKeyValue "ReportSetting$", UCase(sReportSetting)
            oReport_Rpt.nSetKeyValue "RowKey$", Right("00000" & CStr(nRowKey), 5) 
            oReport_Rpt.nSetKey 
            oReport_Rpt.nSetValue "SelectField$", "Last Invoice Date" 
            oReport_Rpt.nSetValue "SelectFieldValue$", "Last Invoice Date" 
            oReport_Rpt.nSetValue "KeyReference$", ""
            oReport_Rpt.nSetValue "Tag$", "Table=SO_SalesOrderHeader;Column=~UDF_LastInvoiceDate$;"
            oReport_Rpt.nSetValue "Operand$", "L" 
            oReport_Rpt.nSetValue "Value1$", "20211204" 
            oReport_Rpt.nSetValue "Value2$", "" 
            oReport_Rpt.nWrite 
            
            oReport_Rpt.nProcessReport "Preview"
            
    		Set oReport_Rpt = Nothing
        End If
    End If

    This is the data in the UDF in SO_SalesOrderHeader.  You have confirmed the UDF is in SO_SalesOrderHeader, correct?

  • 0 in reply to David Speck

    Thanks, David.  I have been manually toggling PrintSalesOrders$ in SO Entry for testing.  And I have confirmed that the UDF is on the SO Header.  I wonder if it's a PU thing.  (We're on PU 3.)  What PU are you running?

  • 0 in reply to David Speck

    I do see that you have some differences in your code.  I will modify mine to match and report back.  Thanks!

  • 0 in reply to David Speck

    So I mimicked your code and still, all orders are being selected.  I'll paste the code here in case you're interested, but I'm thinking it may be our PU.  (Also, we do have multi-bin and scanning mods.  Who knows if that's related.)  I've learned a lot from your feedback, so that's much appreciated.  I'm going to set the SO numbers that I want specifically (because I know that filter works).  It's a bummer, but at least it's a workaround.  Thanks again, David, for your expertise.

  • +1 in reply to n0tgunshy2
    verified answer

    PU10 for 2018.

  • 0 in reply to n0tgunshy2

    	
    'Assign print params
            scModuleCode = oSS.sModuleCode
    			ErrorLog retval, "Error getting module code.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
            scCompanyKey = oSS.sCompanyKey
    			ErrorLog retval, "Error getting company key to " & sCompanyKey, oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
            scReportID = "": retval = oSO.nGetValue("cReportID$", scReportID)
    			ErrorLog retval, "Error getting report ID.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
            sReportSetting = "AUTOPRINT"
    		retval = oSO.nSetTemplateDesc("Plain")
    			ErrorLog retval, "Error setting template to plain.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    			
                nRowKey = nRowKey + 1
                retval = oSO.nSelectReportSetting(sReportSetting)
    				ErrorLog retval, "Error setting report setting.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetKeyValue("ModuleCode$", scModuleCode)
    				ErrorLog retval, "Error setting module code.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetKeyValue("CompanyKey$", scCompanyKey)
    				ErrorLog retval, "Error setting company key.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetKeyValue("ReportID$", scReportID)
    				ErrorLog retval, "Error setting report ID.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetKeyValue("ReportSetting$", UCase(sReportSetting))
    				ErrorLog retval, "Error setting report setting.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetKeyValue("RowKey$", Right("00000" & CStr(nRowKey), 5))
    				ErrorLog retval, "Error setting RowKey", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetKey()
    				ErrorLog retval, "Error setting key.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    				
    				
    				
                retval = oSO.nSetValue("SelectField$", "UDF_Delivery_By")
    				ErrorLog retval, "Error selecting order number field.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetValue("SelectFieldValue$", "UDF_Delivery_By")
    				ErrorLog retval, "Error selecting field value.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetValue("KeyReference$", "")
    				ErrorLog retval, "Error setting key reference.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    			retval = oSO.nSetValue("Tag$", "Table=SO_SalesOrderHeader;Column=~UDF_Delivery_By$;")
    				ErrorLog retval, "Error setting tag.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                retval = oSO.nSetValue("Operand$", "L") 'all orders
    				ErrorLog retval, "Error setting operand.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    			retval = oSO.nSetValue("Value1$", "20211203") 
    				ErrorLog retval, "Error setting UDF_Delivery_By date to " & sDelDate, oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    			retval = oSO.nSetValue("Value2$", "") 
    				ErrorLog retval, "Error clearing Value2", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    				
    				
    
                retval = oSO.nWrite()
    				ErrorLog retval, "Error writing.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
                On Error Resume Next
                retval = oSO.nProcessReport("PRINT")
    				ErrorLog retval, "Error printing.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir '<<<<<<<<<<<<<<<ERROR OCCURS HERE
    				if retval <> 0 then 
    				ErrorLog retval, "Sales Order(s) printed successfully.", oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    				end if
               
    		Set oSO = Nothing

  • 0 in reply to n0tgunshy2

    You could always use the either the SO_SalesOrder_Svc class for read only or the SO_SalesOrder_Bus class for toggling the PrintSalesOrders$ value.  

    Once you have the object, you could use GetResultSets with a filter on the UDF much like with the selection for the report and just return the SalesOrderNo, then split the returned results into an array using Split() with the SEP (ASCII 138) character as the delimiter. 

    Then loop through the array. 

    If you are toggling the PrintSalesOrders$ flag, then you would use SetKey on the sales order number and then update the field and write the change.

    While looping through the array, you can build a comma delimited string to use in the selection criteria of the report on the SalesOrderNo$ field. 

    You could alternatively use the Replace function and replace the SEP character with a comma but you will need to trim the trailing comma and the leading space and comma that GetResultSets adds to the returned values.

  • 0 in reply to David Speck

    Noted.  I'm going to chalk it up to needing the PU. Due to enhancements, we will likely upgrade before we update the PU.  Thanks again, David.

Reply Children
No Data