Print to PDF and electronically deliver Sales Order via BOI

SOLVED

I want to thank everyone in this forum in advance for the wealth of information you have posted and gathered here.
With that information, I have been able to apply a script to automatically print Sales Orders once they are entered.  
The script below runs as a Table - Post Write on the Sales Order Header table.

SONo = ""
oSOPrint = ""
oPaperless = ""

retVal = oBusObj.GetValue("SalesOrderNo$", SONo)

Set oSOPrint = oSession.AsObject(oSession.GetObject("SO_SalesOrderPrinting_rpt"))

retVal = oSOPrint.SelectReportSetting("STANDARD")

oSOPrint.QuickPrint = SONo

'Set Paperless options
Set oPaperless = oSession.AsObject(oSOPrint.coPLCommon) ' Get Paperless object

oPaperless.FormPrintUISelection="7" ' Number of selection in dropbox on the Sales Order Printing Screen

retVal = oSOPrint.ProcessReport("PRINT")

The above script works great to print to PDF.  However, I wanted to also Electronically Deliver the PDF. I changed the oPaperless.FormPrintUISelection setting to 6, but when I do this, it only prints the PDF and it does not Electronically Deliver anything.  Same thing if I change the setting to 2 (Electronically Deliver only).  When I Accept the Order, I see a quick "Sales Order Printing" screen flash, then nothing happens.

Am I missing some PDF setting that will trigger this?  Does anyone have any ideas or input?

Thanks in advance again.

  • 0
    SUGGESTED

    The FormPrintUISelection value is suppose to match one of these values in this order.

  • +1 in reply to David Speck
    verified answer

    Also, you might want to see this post.

    www.sagecity.com/.../308508

  • 0 in reply to David Speck

    Thanks David for sending me in the right direction.  After a bunch of trial and error, I got it to work with the information on that post.  Thanks again!

  • 0 in reply to David Speck

    Hi David,
    Mind if I ask a follow-up on this?  I was able to get this to work with a little tweaking.  The customer is happy with it.  However, I'm hitting a snag if the customer wants to do a quick print after sending the email out.  
    Here are the steps:  1. Customer creates and order.  2. In order for the PDF to go out, they have to check a UDF.  They check it and Accept.  3.  The order is printed and emailed out as desired.  Sales order is closed but the SO Entry window remains open.  4.  Without closing the window, the user opens the same SO and clicks on Quick Print button (to print BarCode form).  They click Print button and get the following error

    If the user actually closed the SO Entry window and reopens it before selecting the SO again, it prints correctly.  So it seems that somehow the .rpt file is still in use when they try to Quick Print.  I tried to use oBusObj.Clear() and oSOPrint = Nothing but it didn't work.  Is there something I can do to either close/reopen the SO Entry screen (or produce the same outcome) or close the .rpt file after printing?

  • 0 in reply to Javier Guzman

    By any chance does the report have a Command added in addition to the *Wrk table table?

  • 0 in reply to David Speck

    No, I'm just using a copy of the standard form code (ISCORDER) to test and I can duplicate it.  For reference, here is my code.  The last two lines do not seem to help.

    SONo = ""
    oSOPrint = ""
    oPaperless = ""
    SOEntered = ""
    
    retVal = oBusObj.GetValue("SalesOrderNo$", SONo)
    retVal = oBusObj.GetValue("UDF_SO_ENTERED", SOEntered)
    
    if SOEntered = "Y"  then
    	Set oSOPrint = oSession.AsObject(oSession.GetObject("SO_SalesOrderPrinting_rpt"))
    
    	retVal = oSOPrint.SelectReportSetting("ISCORDER")
    
    	oSOPrint.QuickPrint = SONo
    
    	'Set EmailSelected property to true
    	oSOPrint.EmailSelected = 1
    
    	'Set Paperless options
    	Set oPaperless = oSession.AsObject(oSOPrint.coPLCommon) ' Get Paperless object
    
    	oPaperless.FormPrintUISelection = "2" ' Number of selection in dropbox on the Sales Order Printing Screen
    
    	' Set Email Engine EESilent property to true
    	'oSOPrint.EmailEngineObj.nEESilent = 1
    
    	' Set Electronic Delivery.  Third argument is the email engine object handle for the from 	object.
    	' Seventh argument is set to true to force no UI when processing
    
    	retval = oPaperless.ElectronicDelivery("",0,oSOPrint.EmailEngineObj,0,"","",1)
    
    	retVal = oSOPrint.ProcessReport("PRINT")
    	set oSOPrint = Nothing
    	retVal = oBusObj.Clear()
    	
    End if

  • 0 in reply to Javier Guzman

    You should actually Clear off the sales order record before processing the report because it will try to update those fields that indicate whether or not the picking sheet and sales order was printed.

    However, if the user has unsaved changes, you would want to prompt if they want to first save the changes before you write the changes. Bus objects have a RecordChanged property you can check, if 0, you can just use oUIObj.BT_Cancel, if 1, you would prompt them using MessageBox like you did in your script that got the cancel reason code before deleting an order. Based on the response, you would then use oUIObj.BT_Accept() and check its returned value to confirm the record was saved successfully, if it failed, it will handle notifying the user why it failed. If it succeeded, you can then start your quick print routine.

    If you want to have the order pulled up after the report is processed, you can use oUIObj.InvokeChange "SalesOrderNo", sSalesOrderNo

  • 0 in reply to David Speck

    I have this script running as a table-post write so I assume it's running the script after the Sales Order has been saved.  That way, I know all changes have been made before doing the Quick Print.

    Can I clear the order after it has been printed?  I assumed it does it automatically after it prints but somehow the printed report (.m4t) file seems to still be in memory or in use.  The only way I know it "clears" this report is by manually closing Sales Order Entry screen and reopening it.  If there is a way of recreating that process through a script (or whatever the system does when closing a screen), maybe I can take the route?

  • 0 in reply to Javier Guzman

    I was thinking it was a button script, having it in the post write event does complicate things i think. What you could try is to store off the key into a variable, since this is just sales order entry the primary key only consists of the SalesOrderNo, you could use either oBusObj.GetKey or oBusObj.GetValue "SalesOrderNo$", then use oBusObj.Clear to release the record, after your quick print routine completes, try putting the business object back on the sales order record using either oBusObj.SetKey or oBusObj.Find, i'm not really sure which is the best method in this case as i'm not entirely sure what the state of a record really is during the post write event, i'm leaning towards trying Find first and see how that goes, then maybe fall back to SetKey.

  • 0 in reply to David Speck

    Sounds good, I'll take that route.  Thank you so much for all your help.  Again, I really appreciate it.