Since you are "quick printing", you shouldn't even need any of the following.
retVal = oReport.SetKeyValue("ModuleCode$", "P/O")
sCompanyKey = oSession.CompanyKey
retVal = oReport.SetKeyValue("CompanyKey$", sCompanyKey) ' "0000000008"
retVal = oReport.SetKeyValue("ReportID$", "PO_PurchaseOrderPrinting_rpt")
retVal = oReport.SetKeyValue("ReportSetting$", sReportSetting)
retVal = oReport.SetKeyValue("RowKey$", "00001")
retSetKey = oReport.SetKey()
If retSetKey = 0 Then
rMsg = oSession.AsObject(oSession.UI).MessageBox("","Could not Set the Key." & vbCRLF & "Last Error" & oReport.LastErrorMsg )
Exit Sub
End If
' Available Operands
' All - "A"
' Begins with - "B"
' Ends with - "E"
' Contains - "C"
' Less than - "L"
' Greater than - "G"
' Range - "R"
' Equal to - "="
' Not Equal to - "N"
' For the next three lines, DFDM inspect the M4L for the appropriate values for the criteria
retVal = oReport.SetValue("SelectField$", "Order Number")
retVal = oReport.SetValue("SelectFieldValue$", "Order Number")
retVal = oReport.SetValue("Tag$", "TABLE=PO_PURCHASEORDERHEADER;COLUMN=PURCHASEORDERNO$;ALELOOKUP=PO_PurchaseOrderAll;")
retVal = oReport.SetValue("Operand$", "=") ' see valid lists above
retVal = oReport.SetValue("Value1$", sPO)
'retVal = oReport.SetValue("Value2$", "02000") ' change operand to "R" for range and uncomment
retVal = oReport.SetValue("KeyReference$", "")
retWrite = oReport.Write() 'saves selection in memory (NOT DISK) so report can operate on it"
If retWrite = 0 Then
rMsg = oSession.AsObject(oSession.UI).MessageBox("","Could not Write report selection into memory." & vbCRLF & "Last Error" & oReport.LastErrorMsg )
Exit Sub
End If
Also, I'm questioning the use of Exit Sub seen above (as well as any point that it occurs after getting an object handle) because that would bypass the method calls to drop the object. You wouldn't really be cleaning up after yourself with that.
I'm guessing when using the PRINT option, you are relying on the user having their correct, default printer configured but perhaps it would be better to always PREVIEW and let them choose to Export/Print from the preview window as they see fit.
------------------------------
David Speck II
Tennessee Software Solutions
------------------------------
Original Message:
Sent: 05-25-2022 17:25
From: Robert Osborn
Subject: Error 0 in Quick Print script
HI Alnoor,
Putting the invokebutton after the getvalue did the trick. i had to remove all the dropobject lines. Now I can customize user screens to hide the print & quick print button so they only have this button and can only print the selected version of the form :-)
Thanks so much!!!
------------------------------
Bob Osborn
Consultant
ACI Consulting
------------------------------
Original Message:
Sent: 05-25-2022 16:11
From: Alnoor Cassim
Subject: Error 0 in Quick Print script
Oh this whole time I thought you were in S/O Entry trying to print a DropShip PO but now I understand you're actually in P/O Entry trying to "quick print" your own PO and set your own Form Code without having to click the Quick Print button. Do I have that right? That would explain why you get Error 0 because the system is trying to update the current PO to set the PrintPurchaseOrders flag to Y. I haven't tested but you may want to try, after you GetValue() on the PurchaseOrderNo (which can alternatively be sPO=oBusObj.GetKey() ) to then oScript.InvokeButton("BT_ACCEPT") as that would clear the screen, clear the record, and set the EditState to 0. However I don't know if the script would stop executing at that point.
------------------------------
Alnoor Cassim
Email: alnoor@asifocus.com
Ph:
Original Message:
Sent: 05-25-2022 14:51
From: Robert Osborn
Subject: Error 0 in Quick Print script
Hi Alnoor/All,
I have made the changes to the script (I put the clear and dropobject in several places as I was not sure "when" it should be done) but the error persists. What I was really hoping to find is how to either close the screen or clear the record when the script starts to run. Seems like that would solve the issue but can't find anything on how to accomplish it.
' In PO Entry, click a button to quick print PO with specific form code' QuickPrintFromPOEntry.txt' Desc: In PO Entry, click a button to quick print the PO using specific form code ' Bus Object: PO_PurchaseOrderPrinting_rpt' Event: Button' By Bob Osborn, ACI' Version 1.01'Version History' ' 1.01 - 2022-05-20 Original' ----------------------------- SCRIPT START ------------------------------------------------------Call PrintPurchaseOrder()' Done this way to accomodate Exit Sub' Better than WScript.QuitSub PrintPurchaseOrder() ' Note that because we are in a button the main business object is always the header object ' So we have to reference the Lines separately sPO = "" retVal = oBusObj.GetValue("PurchaseOrderNo$", sPO) 'Instantiate P/O Printing 'If Not(IsObject("PO_PurchaseOrderPrinting_rpt")) Then If IsObject(oReport)=False Then Set oReport = oSession.AsObject(oSession.GetObject("PO_PurchaseOrderPrinting_rpt")) End If 'Set the oh so important QuickPrint flag else prompt to print Picking Sheets attempts to appear and form never prints oReport.QuickPrint = sPO ' Place the Sy_ReportSelection row into edit state to allow selections sReportSetting = "TEST" retVal = oReport.SelectReportSetting(sReportSetting) If retVal = 0 Then sMsg = "Could not select the TEST form code." & vbCRLF & "Last Error: " & oReport.LastErrorMsg rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg) Exit Sub End If retVal = oReport.SetKeyValue("ModuleCode$", "P/O") sCompanyKey = oSession.CompanyKey retVal = oReport.SetKeyValue("CompanyKey$", sCompanyKey) ' "0000000008" retVal = oReport.SetKeyValue("ReportID$", "PO_PurchaseOrderPrinting_rpt") retVal = oReport.SetKeyValue("ReportSetting$", sReportSetting) retVal = oReport.SetKeyValue("RowKey$", "00001") retSetKey = oReport.SetKey() If retSetKey = 0 Then rMsg = oSession.AsObject(oSession.UI).MessageBox("","Could not Set the Key." & vbCRLF & "Last Error" & oReport.LastErrorMsg ) Exit Sub End If ' Available Operands ' All - "A" ' Begins with - "B" ' Ends with - "E" ' Contains - "C" ' Less than - "L" ' Greater than - "G" ' Range - "R" ' Equal to - "=" ' Not Equal to - "N" ' For the next three lines, DFDM inspect the M4L for the appropriate values for the criteria retVal = oReport.SetValue("SelectField$", "Order Number") retVal = oReport.SetValue("SelectFieldValue$", "Order Number") retVal = oReport.SetValue("Tag$", "TABLE=PO_PURCHASEORDERHEADER;COLUMN=PURCHASEORDERNO$;ALELOOKUP=PO_PurchaseOrderAll;") retVal = oReport.SetValue("Operand$", "=") ' see valid lists above retVal = oReport.SetValue("Value1$", sPO) 'retVal = oReport.SetValue("Value2$", "02000") ' change operand to "R" for range and uncomment retVal = oReport.SetValue("KeyReference$", "") retWrite = oReport.Write() 'saves selection in memory (NOT DISK) so report can operate on it" If retWrite = 0 Then rMsg = oSession.AsObject(oSession.UI).MessageBox("","Could not Write report selection into memory." & vbCRLF & "Last Error" & oReport.LastErrorMsg ) Exit Sub End If 'Set the TempalteDesc value - needed for 2013 and higher Sage100Version = "" retVal = oSession.GetParameter("SYS", "Version$", Sage100Version) MajorVersion = CSng(Left(Sage100Version, 3)) If CSng(MajorVersion) >= 5 Then retVal = oReport.SetPartialRecord("TEST", oScript.Evaluate("CPL(""IOLIST TemplateDesc$"")")) End If rtnVal = oReport.ProcessReport("PRINT") If rtnVal = 0 Then sMsg = "Last error on ProcessReport = " & oReport.LastErrorMsg rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg) End If RetVal=oReport.Clear() If IsObject(oReport)=True Then oSession.DropObject("PO_PurchaseOrderPrinting_rpt") sMsg = "About to PREVIEW Sales Order No " & sPO ' rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg) 'retVal = oReport.ProcessReport("PREVIEW") ' other options include "DEFERRED" ' retVal = oReport.ProcessReport("PRINT") ' "PRINT" will print to default printer OR saved settingIf IsObject(oReport)=True Then oSession.DropObject("PO_PurchaseOrderPrinting_rpt")RetVal=oReport.Clear()'oSession.DropObject("PO_PurchaseOrderPrinting_rpt")If IsObject(oReport)=True Then oSession.DropObject("PO_PurchaseOrderPrinting_rpt")End Sub
------------------------------
Bob Osborn
Consultant
ACI Consulting
Original Message:
Sent: 05-21-2022 17:27
From: Alnoor Cassim
Subject: Error 0 in Quick Print script
Multi-part answer:
Where it says:
If Not(IsObject("PO_PurchaseOrderPrinting_rpt"))
Let's change that to:
If IsObject(oReport)=False Then
Also the DropObject at the end can use some help. 2 ideas:
1. Check to see if object actually needs to be dropped with IsObject. IOW change it to:
If IsObject(oReport)=True Then oSession.DropObject("PO_PurchaseOrderPrinting_rpt")
2. Even better combine the IsObject check with David's technique of getting the specific numeric object handle so you can precisely drop the correct instance of the object
If IsObject(oReport)=False Then
nReport = oSession.GetObject("PO_PurchaseOrderPrinting_rpt") 'get the numeric handle
If nReport <> 0 Then Set oReport = oSession.AsObject(nReport) 'Set oReport as an obj
End If
'Later in the script send the numeric handle to the DropObject
If IsObject(oReport)=True Then oSession.DropObject nReport
------------------------------
Alnoor Cassim
Email: alnoor@asifocus.com
Ph: