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

  • 0

    I'm not sure if it matters, but I use oBusObj.GetNextSalesOrderNo(soNum) to set the next order number.

    What does the LastErrorMsg give you?

  • 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?

  • +1
    verified answer

    oScript.InvokeButton queues buttons to be invoked after the script finishes IIRC so you can attempt to force it to occur immediately if you follow it with oUIObj.HandleScriptUI but you might want to instead consider calling the UI object's method for the get next number button, in your UI post load script, this should be possible with oUIObj.BT_NextNum then use oUIObj.InvokeChange for the customer number but you would need to use ML_Customer as the field name instead of CustomerNo.

  • 0 in reply to David Speck

    As always, David coming in clutch with the save!  Thanks for that information, David.  You are right:  Making those quick changes and using the ML_Customer as the field name instead of Customer Number made this work!

    Thanks again and again.  Have a great weekend!

  • 0 in reply to David Speck

    David, quick follow-up.

    This script works great.  However, I also have the "Quick print SO" script (found here)  which is a Table Post-Write script on Sales Order Entry, and it is not working correctly after I enter an order and click Accept.  I know it does load up the SY_ReportCommon since I can see it in the traceWindow but then nothing happens.  It does not print anything.

    I assume it's because this current script is launching within the AR_Customer_Bus and not the SO_SalesOrder_Bus?  I did try to add oSession.NewObject("SO_SalesOrder_Bus") to this script but that didn't do anything.  Not sure if I need to create another script for this situation that mimics what Quick Print SO script is doing or what.

  • 0 in reply to Javier Guzman

    Maybe not SO_SalesOrder_Bus but SY_service?  I noticed it loads SY_Service when I open AR_Customer but when I click on the button to launch the SO entry screen and populate the new SO number and Customer number, there is no new SY_Service.  Could that be it?  If so, how can I change it so the correct service loads up?

  • 0 in reply to Javier Guzman

    in your quick print script, are you filtering for the oSession.StartProgram being equal to SO_SalesOrder_UI?

    If you are, then that is likely why it isn't working since the button is being launched from Customer Inquiry/Maintenance, the StartProgram is going to be AR_Customer_UI.  Since you are using the Process method, IIRC, that will save off and suspend the script at that point in customer maintenance.  You can then save off the current start program into a variable at the beginning of you button script in customer maintenance and then set the program to SO_SalesOrder_UI prior to getting your object handle to SO_SalesOrder_UI and calling the Process method, then once the user is done in sales order entry and they close the task, your script in customer maintenance should resume and you would then set the start program back to what you saved into the variable at the beginning of the script.  An easy way to do this is to save the value in the oSession.StartTask property, this is numeric, you can then just use oSession.SetProgram nOriginalStartTask.  If you use oSession.StartProgram, you'll have to do the compound methods with LookupTask and SetProgram, like this, oSession.SetProgram oSession.LookupTask(sOriginalStartProgram).

  • 0 in reply to David Speck

    Hi David,
    Thanks for your reply.  In my table-postwrite QuickPrint SO script I do am not filtering for oSession.StartProgram.  Maybe I should?

    For quick reference, here is that script:

    SONo = ""
    oSOPrint = ""
    oPaperless = ""
    SOEntered = ""
    PrintSO = ""
    
    retVal = oBusObj.GetValue("SalesOrderNo$", SONo)
    retVal = oBusObj.GetValue("UDF_SO_ENTERED", SOEntered)
    retVal = oBusObj.GetValue("PrintSalesOrders$", PrintSO)
    
    if SOEntered = "Y" and PrintSO = "Y" then
    	oScript.DebugPrint "SOEntered: " & SOEntered & ", PrintSO: " & PrintSO & " SONo: " & SONo
    	nSOPrint = 0 : nSOPrint = oSession.NewObject("SO_SalesOrderPrinting_rpt") ' Return this into a numeric variable so it can be dropped later since the oSession.DropObject method does not support VBScript Objects passed as an argument and i have not been able to figure out a way to convert or extract a VBScript object back to a numeric handle like Sage 100 uses.
    	oScript.DebugPrint "nSOPrint: " & nSOPrint
    	oScript.DebugPrint oBusObj.LastErrorMsg
    	If nSOPrint <> 0 Then
    		Set oSOPrint = oSession.AsObject(nSOPrint)
    		oScript.DebugPrint oSOPrint
    		retVal = oSOPrint.SelectReportSetting("ISCORDER")
    		oSOPrint.QuickPrint = SONo
    		'Set EmailSelected property to true
    		oSOPrint.EmailSelected = 1
    		'Set Paperless options
    		Set oPaperless = oSession.AsObject(oSOPrint.coPLCommon) ' Get Paperless object
    
    		oPaperless.FormPrintUISelection = "2" ' Number of selection in dropbox on the SO Printing Screen
    
    		' Set Email Engine EESilent property to true
    		'oSOPrint.EmailEngineObj.EESilent = 1
    
    		' Set Electronic Delivery.  Third argument is the email engine object handle for the from object.
    		' Seventh argument is set to true to force no UI when processing
    
    		retval = oPaperless.ElectronicDelivery("",0,oSOPrint.EmailEngineObj,0,"","",1)
    
    		retVal = oSOPrint.ProcessReport("PRINT")
    		set oSOPrint = Nothing
    		oSession.DropObject nSOPrint ' Drop the numeric object handle for the class created using GetObject/NewObject
    	End if
    End if

    One thing to note:  When I open Sales Order (not from Customer Maintenance) and I create a new order and Accept it, the Quick Print SO script above launches perfectly.  I did notice that the nSOPrint value changes every single time there is a new order printed.  However, when I launch SO entry from my button script in Customer Maintenance and I enter a new order and Accept it, the nSOPrint value is ALWAYS the same:  100237.  Since it's a numeric value of SO_SalesOrderPrinting.rpt, maybe it's not loading correctly when launching from Customer Maintenance?

  • 0 in reply to Javier Guzman

    After the ProcessReport method is called, write the retVal and oSOPrint.LastErrorMsg to the trace window or display it in a message box to see if there is anything to indicate why it isn't working.  You may have to set the oSOPrint.LastErrorMsg property to a blank string prior to calling the ProcessReport method in case it gets set prior to the ProcessReport method being called.