How do I run a script after a sales order is really saved?

I need to run a script after a sales order is saved.  The Post-Write doesn't work, because the data is not yet in the tables when the Post-Write script runs.  My script prints a specific sales order form for the order being saved, but on new orders, since the data is not really in the tables yet, the form comes up blank.  Is there a way to trigger something truly after the data is saved? 

  • 0

    My 1st thought is can they instead just click the Print Order (aka Quick Print) button and then change the form code to the correct one? It will "remember" the same form code the next time you quick print.

    ** I can confirm the physical write / update of the lines occur after Post-Write and there is no other script event / procedure you can fire from. The same issue you describe with new orders also occurs if you were editing an existing order and changed any of the line data (qtys, item code, etc). In that case your changes wouldn't appear when your script fires off. 

    If you can't do quick print then suggest 1 of the 2 things:

    1a- Create a simpler Post-Write script to write the Order No to a UDT you've created to hold Order Numbers to be printed. Make the Order No the key field and add a UDF for the form code. Your Pre-Write will write both the Order No and Form Code to the UDT. 

    1b- Convert your current Post-Write script into a BOI script that will auto-run (via Windows Task Scheduler or whatever) every X minutes to poll the UDT. Whatever Order Numbers it finds, it prints those using the correct form code then deletes those UDT records.

    1c- Create a Post-Delete script in case the user intentionally deletes the order so you can delete the order row from the UDT. But don't fire off  If oSession.Updating > 0 because normal deletes occur via SO Sales Journal Update well after printing the order. 

    2- Contact a MD. I've been in that role where in Quick Print screen I would override the form code or the Paperless setting based on the conditions in the order.

  • 0 in reply to Alnoor

    Your 1st thought is what they do now, but because they only need print this form for certain items, the users often forget.  So my script checks the lines and if the form is required, prints it for them.  I had overcome the issue with editing by pulling the fields from the SO Sales Order History table - which does get updated before the Post Write on an existing order - but not on a new order. 

    I was considering your second solution but trying to avoid it.  It's nice to hear it validated.  However, it doesn't sound like it's possible to avoid.  Thanks for the reminder about deleted orders though - i hadn't thought of that.