Script to Export SO

SUGGESTED

I'm working on a button script ("Execute on Server" selected, MAS 200) that will export a PDF of a Sales Order to a specific location without prompting the user. I'm running into some strange issues and was hoping someone has seen some of these things before. First, here is my script so far:

'Script to "export" SO to file

'Init VARs
sSONum = ""

dim path
path = "\\fileserver\Sage_Server\email_files\"

nOutputFormat = 0
sOutputPath = ""

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

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

retVal = oSOPrint.SetOptions(options)
oSOPrint.ReportType = 6

retval = oSOPrint.InitReportEngine()

retVal = oSOPrint.SelectReportSetting("SOFORM")

nOutputFormat = 5
sOutputPath = path & "Order_" & sSONum & ".pdf"
retVal = oSession.AsObject(oSession.UI).MessageBox("",sOutputPath)

retval = oSOPrint.SetExportOptions(nOutputFormat, sOutputPath)

retVal = oSOPrint.ProcessReport("EXPORT")

retVal = oSession.AsObject(oSession.UI).MessageBox("",osession.lasterrormsg)

The strange things that are happening is the sOutputPath is displaying with no "\" and where the "\" should be, there are new lines. So instead of "\\fileserver\Sage_Server\email_files\Order_123456.pdf", I'm getting:

fileserver

Sage_Server

email_files

Order_123456.pdf

No matter how I add quotes or additional backslashes, I can't seem to get it to display properly. I'm assuming that's part of the problem of it not exporting the PDF.

The other strange thing is that the oSession.LastErrorMsg is displaying as: "Module P/R is not on file." We DON'T have the payroll module, but that shouldn't even be trying to use that module. Hopefully it's something simple that's wrong in my code (I did a lot of reverse engineering of it from various semi-related posts on here). Thanks in advance!

  • 0 in reply to chuntley87

    When asked for an improved user process to customize messages and add attachments, I usually go one of two routes:

    • Use a 3rd party tool to generate the PDF's / emails (Visual Cut, not Paperless Office).

    or

    • Configure Paperless to send the email to an internal email address, where the user can take that and forward it to the customer, adding / editing whatever they want from within Outlook.
  • 0 in reply to Kevin M

    Both of Kevin's suggestions are good but if you want to continue with what you already have in place, to avoid the message about the record in use, you simply have to get off the record before you invoke your exporting/printing of the order.

    You can achieve this by checking the oBusObj.RecordChanged property, if 0, then you can invoke the oUIObj.BT_Cancel method, if 1, then use the MessageBox method to display a message box with your choice of words to inform the user that the record has been changed and ask the user if they want to save the changes before emailing the order. Depending on the return value of the MessagBox method, if YES, then invoke and check the return value of the oUIObj.BT_Accept() method, if 1, proceed with your script, if not 1, do not proceed, the user should get a warning from sage 100 as to why the attempt to save the order failed.

    EDIT: If you are not very familiar with the MessageBox method, check the file layouts and program information and expand Object Reference > Base System > SY_UI then view the section for MessageBox, that will show you how to use it with buttons to get a response from the user.

  • 0 in reply to David Speck

    David,

    Thanks for the ideas. It seems to still be throwing the same error even when I invoke BT_ACCEPT before I begin the SO Printing routine. So it's not 'fully' exiting the order until the script is finished, it looks like.

    Maybe it just isn't possible to script a SO to export to a file in Sage 100, without an error. 

  • 0 in reply to chuntley87
    SUGGESTED

    How are you invoking BT_Accept? if you used my example (oUIObj.BT_Accept), it should happen immediately, if you are using oScript.InvokeButton, it isn't happening until your script finishes executing.

  • 0 in reply to David Speck

    David,

    Thank you so much for that! That did it. The only small issue is I can't seem to get it to work perfectly from a dialog box. It leaves the dialog box open, but exports the PDF and emails it with no errors. When it's done, the dialog box is open (but blank), and when you click "OK" to close the dialog box, the Sales Order is in sort of a limbo state. It's all greyed out, but not back to the header tab ready for a new order. You have to click "Accept" or "Cancel" to get back. If you run my script from the Totals tab (not from the dialog), everything works perfectly. I'll play around with it some more, but so far neither oUIObj.BT_OK or oScript.InvokeButton("BT_OK") works to close the dialog box first. Not sure why that is, but either way, it's not a dealbreaker.

    Thanks again to everyone who helped me on this!

  • 0 in reply to chuntley87

    Have you ever figured how to close dialog? I am having the same issue and this is not working for me on 2018 Sage 100 advanced:

    retVal = oScript.InvokeButton("BT_OK")
    retVal = oUIObj.HandleScriptUI()

    Thanks

  • 0 in reply to ZoomZoom

    I ended up scrapping the dialog box and used a "hidden" panel. Basically I added a panel and gave it a blank name so it doesn't show up in the UI. 

  • 0 in reply to chuntley87

    Came across this post while researching a related issue... would you mind posting your final script for posterity? I think your implementation of BT_Accept is what I need currently, but does not appear in the script as posted above. Thank you very much in advance!

  • 0 in reply to jcbaker

    I ended up abandoning the project (I may revisit later, just got so busy with other things). From what I remember, everything worked, but it still through an error message and then left the SO in an unresponsive state after sending, requiring you to essentially "kill" the process of the SO to move on. I never even got to the UDT to store users' email address and passwords. I'll scrub through my script and take out passwords and whatnot and post shortly.

  • 0 in reply to chuntley87

    OK, looks like my the script I posted above is the last version I have saved, except right before the 'export PDF line, I added:

    oUIObj.BT_ACCEPT

    Again, I haven't looked at this in about 9 months, so it's gotten sort of "stale" in my head. Hope this helps somebody else. Everybody at my work really hates the email part of Sage, so I'm sure I'll take another shot at it soon.