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!