Scripting

  • 1.  Hi There,Working on a Sales Order Invoicing scri

    Posted 03-27-2017 09:08
      |   view attached
    Hi There, Working on a Sales Order Invoicing script for a customer. They have orders come in with 'pending' Purchase order numbers from the customer. In these cases will will have them check a udf box ""Po Needed"" so the final purchase order number can be entered when the s/o is Invoiced. I then want a script that will look at the udf value when they are INVOICING and displays a message if the box is checked but the PO number has not yet been entered (this check occurs on pretotals). I have put the following together: '****************script snip start**************** 'Prevent Sales Order from being accepted if PO is checked and po field is blank 'Bus Object: SO_InvoiceHeader_bus 'Event: Pre-Write retVal = oScript.DebugPrint(""*Start Script SO Invoice PO Number Req'd Script.txt***"") ' -------------------------SCRIPT START ------------------------------------ sPOChecked = """" sPOValue = """" retval = oBusObj.getvalue(""UDF_PO_NEEDED$"",sPOChecked) 'get value of the PO Check udf retval = oBusObj.getvalue(""CustomerPONo$"",sPOValue) 'get value of the PO field 'if required and the user did not fill in a Purchase Order value then do this: If sPOChecked =""Y"" then 'if PO Needed checkbox was checked at sales order entry time if sPOValue = """" then 'but the PO number is still blank when invoicing then give the error sMsg = ""Please fill in the Purchase Order Number."" msgRetVal = oSession.AsObject(oSession.UI).MessageBox("""", sMsg) 'show message box to user retVal = oScript.SetError(sMsg) retVal = oScript.InvokeButton(""fldr.pHeader"") 'go back to header tab so user can easily enter missing info end if '******************script snip end*************** Well it works ok on the invoicing side of things, but the trouble is that it is firing when I enter the Sales Order! When entering the order initially I check the UDF Po Needed box(on sales order header screen), enter a few lines and when I go to the Totals it fires(so pretotals on Sales Order Header causes the script to fire). I have double checked that it is set to run on SO Invoice Header pretotals (see screen attachment). I double checked the two 'get values' in the script are from the so invoice header table as well. This is probably scripting 101 question, but i can't seem to figure out what is triggering it to run on the Order screen AND the Invoicing screen. I just need it to fire on the Invoicing screen. Ideas? Thanks!


  • 2.  RE: Hi There,Working on a Sales Order Invoicing scri

    Posted 03-27-2017 09:18
    You can put in an additional check for the start program at the very beginning of the script. '---------------------------------------------------------------------------- if oSession.StartProgram = ""SO_INVOICE_UI"" then ' do stuff here. end if '----------------------------------------------------------------------------


  • 3.  RE: Hi There,Working on a Sales Order Invoicing scri

    Posted 03-27-2017 09:56
    Thank you @DavidSpeckII - I will give this a try.


  • 4.  RE: Hi There,Working on a Sales Order Invoicing scri

    Posted 03-27-2017 10:02
    also, forgot to mention that if there other things going on like VI jobs or external BOI scripts that might create invoices and you only want the script to fire when it is being used with a UI, then you can use the following. It makes sure the start program is SO_Invoice_Ui (this can be set by other scripts too) and that the screen (library) name is SO_Invoice.m4l. '---------------------------------------------------------------------------- If IsObject(oUIObj) = False And CBool(oScript.UIObj) Then Set myUIObj = oSession.AsObject(oScript.UIObj) If UCase(oSession.StartProgram) = ""SO_INVOICE_UI"" And UCase(myUIObj.GetScreenName()) = ""SO_INVOICE.M4L"" Then ' do stuff here. End If Set myUIObj = Nothing End If '----------------------------------------------------------------------------


  • 5.  RE: Hi There,Working on a Sales Order Invoicing scri

    Posted 03-27-2017 10:18
    also, although i just tested this on v2015 and i was unable to get a script assigned to SO invoice pre totals to fire when i am in SO sales order entry. Are you sure you don't have any scripts assigned to any events on SO sales order header that may be calling the same script ID?


  • 6.  RE: Hi There,Working on a Sales Order Invoicing scri

    Posted 03-27-2017 10:53
    Marc, Take a look in the cm\scripts directory and see if there is a SO_SalesOrder_bus.vbs file in that directory. This would get run whenever the business object is run. You can open the file with notepad and see if the text of you script is in there.