Launch Sales Order Entry to create new order from Customer Maintenance and pass Customer Number

SOLVED

Hi Sage City and Happy Friday!

I have been working on a button script to launch Sales Order Entry from AR Customer Maintenance.  The goal is to click on the button and open SO Entry, automatically select the next Order Number and pass the Customer Number to it.  I thought it was simple enough but I cannot pass the Customer Number for some reason.

Here is what I have.  I created a new button in AR Customer Main.  It is linked to the script below

oSOEntry = 0
DivNo = ""
CustNo = ""
oSessionScript = 0
sPopupFlag = 0
SODivNo = ""
SOCustNo = ""
sFlag = 1
CustNumber = ""

oSOEntry = oSession.GetObject("SO_SalesOrder_UI")
retVal = oBusObj.GetValue("ARDivisionNo$",DivNo)
retVal = oBusObj.GetValue("CustomerNo$",CustNo)

CustNumber = DivNo&"-"&CustNo

oScript.DebugPrint CustNumber

if oSOEntry <> 0 then
	Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
	retVal = oSessionScript.SetStorageVar("sPopupFlag", sFlag)
	retVal = oSessionScript.SetStorageVar("SODivNo", DivNo)
	retVal = oSessionScript.SetStorageVar("SOCustNo",CustNo)
	retVal = oSessionScript.SetStorageVar("CustNumber",CustNumber)
	oScript.DebugPrint DivNo & "-" & CustNo
	Set oSOEntry = oSession.AsObject(oSOEntry)
	retVal = oSOEntry.Process()

End if

Everything is good to go up to this point.  Then, I have the following Panel-PostLoad script on PHEADER of Sales Order Entry (it wouldn't work on DMAIN for some reason)

sFlag = 0
sPopupFlag = 0
oSessionScript = 0
SODivNo = ""
SOCustNo = ""
DivNo = ""
CustNo = ""
CustNumber = ""

Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
retVal = oSessionScript.GetStorageVar("sPopupFlag",sFlag)
retVal = oSessionScript.GetStorageVar("SODivNo", DivNo)
retVal = oSessionScript.GetStorageVar("SOCustNo",CustNo)
retVal = oSessionScript.GetStorageVar("CustNumber", CustNumber)
oScript.DebugPrint "sFlag= " & sFlag & " Div= " & DivNo & " CustNo= " & CustNo
oScript.DebugPrint CustNumber

if sFlag <> 0 and sScriptRun = 0 Then
	sFlag = 0 : retVal = oSessionScript.SetStorageVar("sPopupFlag",sFlag)
	retVal = oScript.InvokeButton("BT_NEXTNUM")
	retVal = oBusObj.SetValue("ARDivisionNo$", DivNo)
	retVal = oBusObj.SetValue("CustomerNo$",CustNo)
	oScript.DebugPrint oBusObj.LastErrorMsg
	
end if

When I click the button from Customer Maintenance, it is definitely getting the Division and Customer number and setting it into StorageVar.  The Panel-Postload script is getting the variables as it launches the screen and clicks on the "Next SO number" button.  However, I cannot get it to set the Division Number and Customer number.  I tried to set "oBusObj.Write()" after setting the values but that didn't work either since I assume that's writing the whole record and it's missing a whole bunch of info.
Maybe I have the script in the wrong place (DMAIN instead of PHEADER) and I need to use a different method?  Or maybe I need to use InvokeProgram but I thought you couldn't pass variables that way?  
Any ideas would be greatly appreciated.
Thanks!

Javier

Parents Reply Children
  • 0 in reply to hyanaga

    I tried that at some point but it didn't seem to work, either.  The last error gives me "Missing Record to Calculate Taxes"

  • 0 in reply to hyanaga

    I assume the reason why it doesn't show is because I'm using the UI?   I noticed that when you manually create an order and select a Customer number, then look into DFDM at the SO_SalesOrderHeader record, the Division and Cust Number are not written, only the Sales Order number, OrderType, OrderDate, OrderStatus and ShipExpireDate.  So maybe I have the script launch the Customer List Lookup, enter the customer number, and press the Select button via UI?  Is that possible?